Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.844
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.844
Problem:    Enum is not indented correctly with "public" etc.
Solution:   Skip "public", "private" and "protected". (Hong Xu)
Files:	    src/misc1.c


*** ../vim-7.3.843/src/misc1.c	2013-02-13 16:10:13.000000000 +0100
--- src/misc1.c	2013-03-07 12:59:45.000000000 +0100
***************
*** 5275,5280 ****
--- 5275,5281 ----
  static int	cin_is_cpp_baseclass __ARGS((colnr_T *col));
  static int	get_baseclass_amount __ARGS((int col, int ind_maxparen, int ind_maxcomment, int ind_cpp_baseclass));
  static int	cin_ends_in __ARGS((char_u *, char_u *, char_u *));
+ static int	cin_starts_with __ARGS((char_u *s, char *word));
  static int	cin_skip2pos __ARGS((pos_T *trypos));
  static pos_T	*find_start_brace __ARGS((int));
  static pos_T	*find_match_paren __ARGS((int, int));
***************
*** 5446,5469 ****
  }
  
  /*
!  * Recognize structure initialization and enumerations.
!  * Q&D-Implementation:
!  * check for "=" at end or "[typedef] enum" at beginning of line.
   */
      static int
  cin_isinit(void)
  {
      char_u	*s;
  
      s = cin_skipcomment(ml_get_curline());
  
!     if (STRNCMP(s, "typedef", 7) == 0 && !vim_isIDc(s[7]))
  	s = cin_skipcomment(s + 7);
  
!     if (STRNCMP(s, "static", 6) == 0 && !vim_isIDc(s[6]))
! 	s = cin_skipcomment(s + 6);
  
!     if (STRNCMP(s, "enum", 4) == 0 && !vim_isIDc(s[4]))
  	return TRUE;
  
      if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
--- 5447,5486 ----
  }
  
  /*
!  * Recognize structure initialization and enumerations:
!  * "[typedef] [static|public|protected|private] enum"
!  * "[typedef] [static|public|protected|private] = {"
   */
      static int
  cin_isinit(void)
  {
      char_u	*s;
+     static char *skip[] = {"static", "public", "protected", "private"};
  
      s = cin_skipcomment(ml_get_curline());
  
!     if (cin_starts_with(s, "typedef"))
  	s = cin_skipcomment(s + 7);
  
!     for (;;)
!     {
! 	int i, l;
! 
! 	for (i = 0; i < (int)(sizeof(skip) / sizeof(char *)); ++i)
! 	{
! 	    l = strlen(skip[i]);
! 	    if (cin_starts_with(s, skip[i]))
! 	    {
! 		s = cin_skipcomment(s + l);
! 		l = 0;
! 		break;
! 	    }
! 	}
! 	if (l != 0)
! 	    break;
!     }
  
!     if (cin_starts_with(s, "enum"))
  	return TRUE;
  
      if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
***************
*** 5481,5487 ****
      int strict; /* Allow relaxed check of case statement for JS */
  {
      s = cin_skipcomment(s);
!     if (STRNCMP(s, "case", 4) == 0 && !vim_isIDc(s[4]))
      {
  	for (s += 4; *s; ++s)
  	{
--- 5498,5504 ----
      int strict; /* Allow relaxed check of case statement for JS */
  {
      s = cin_skipcomment(s);
!     if (cin_starts_with(s, "case"))
      {
  	for (s += 4; *s; ++s)
  	{
***************
*** 6049,6055 ****
      p = cin_skipcomment(p);
      if (*p == '}')		/* accept "} while (cond);" */
  	p = cin_skipcomment(p + 1);
!     if (STRNCMP(p, "while", 5) == 0 && !vim_isIDc(p[5]))
      {
  	cursor_save = curwin->w_cursor;
  	curwin->w_cursor.lnum = lnum;
--- 6066,6072 ----
      p = cin_skipcomment(p);
      if (*p == '}')		/* accept "} while (cond);" */
  	p = cin_skipcomment(p + 1);
!     if (cin_starts_with(p, "while"))
      {
  	cursor_save = curwin->w_cursor;
  	curwin->w_cursor.lnum = lnum;
***************
*** 6156,6162 ****
  		    s = cin_skipcomment(ml_get(trypos->lnum));
  		    if (*s == '}')		/* accept "} while (cond);" */
  			s = cin_skipcomment(s + 1);
! 		    if (STRNCMP(s, "while", 5) == 0 && !vim_isIDc(s[5]))
  		    {
  			curwin->w_cursor.lnum = trypos->lnum;
  			return TRUE;
--- 6173,6179 ----
  		    s = cin_skipcomment(ml_get(trypos->lnum));
  		    if (*s == '}')		/* accept "} while (cond);" */
  			s = cin_skipcomment(s + 1);
! 		    if (cin_starts_with(s, "while"))
  		    {
  			curwin->w_cursor.lnum = trypos->lnum;
  			return TRUE;
***************
*** 6406,6411 ****
--- 6423,6441 ----
  }
  
  /*
+  * Return TRUE when "s" starts with "word" and then a non-ID character.
+  */
+     static int
+ cin_starts_with(s, word)
+     char_u *s;
+     char *word;
+ {
+     int l = STRLEN(word);
+ 
+     return (STRNCMP(s, word, l) == 0 && !vim_isIDc(s[l]));
+ }
+ 
+ /*
   * Skip strings, chars and comments until at or past "trypos".
   * Return the column found.
   */
*** ../vim-7.3.843/src/version.c	2013-02-26 22:54:06.000000000 +0100
--- src/version.c	2013-03-07 13:12:20.000000000 +0100
***************
*** 730,731 ****
--- 730,733 ----
  {   /* Add new patch number below this line */
+ /**/
+     844,
  /**/

-- 
Now it is such a bizarrely improbable coincidence that anything as
mind-bogglingly useful as the Babel fish could have evolved purely by chance
that some thinkers have chosen to see it as a final and clinching proof of the
NON-existence of God.
The argument goes something like this: 'I refuse to prove that I exist,' says
God, 'for proof denies faith, and without faith I am nothing.'
'But,' says Man, 'the Babel fish is a dead giveaway, isn't it?  It could not
have evolved by chance.  It proves you exist, and so therefore, by your own
arguments, you don't.  QED.'
'Oh dear,' says God, 'I hadn't thought of that,' and promptly vanishes in a
puff of logic.
'Oh, that was easy,' says Man, and for an encore goes on to prove that black
is white and gets himself killed on the next pedestrian crossing.
		-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///