Karsten Hopp b7944f
To: vim_dev@googlegroups.com
Karsten Hopp b7944f
Subject: Patch 7.3.178
Karsten Hopp b7944f
Fcc: outbox
Karsten Hopp b7944f
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b7944f
Mime-Version: 1.0
Karsten Hopp b7944f
Content-Type: text/plain; charset=UTF-8
Karsten Hopp b7944f
Content-Transfer-Encoding: 8bit
Karsten Hopp b7944f
------------
Karsten Hopp b7944f
Karsten Hopp b7944f
Patch 7.3.178
Karsten Hopp b7944f
Problem:    C-indent doesn't handle code right after { correctly.
Karsten Hopp b7944f
Solution:   Fix detecting unterminated line. (Lech Lorens)
Karsten Hopp b7944f
Files:      src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
Karsten Hopp b7944f
    
Karsten Hopp b7944f
Karsten Hopp b7944f
*** ../vim-7.3.177/src/misc1.c	2011-04-28 17:48:39.000000000 +0200
Karsten Hopp b7944f
--- src/misc1.c	2011-05-10 11:35:09.000000000 +0200
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 4983,4989 ****
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  /*
Karsten Hopp b7944f
!  * Return TRUE if there there is no code at *s.  White space and comments are
Karsten Hopp b7944f
   * not considered code.
Karsten Hopp b7944f
   */
Karsten Hopp b7944f
      static int
Karsten Hopp b7944f
--- 4983,4989 ----
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  /*
Karsten Hopp b7944f
!  * Return TRUE if there is no code at *s.  White space and comments are
Karsten Hopp b7944f
   * not considered code.
Karsten Hopp b7944f
   */
Karsten Hopp b7944f
      static int
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 5458,5465 ****
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  /*
Karsten Hopp b7944f
!  * Recognize a line that starts with '{' or '}', or ends with ';', '{' or '}'.
Karsten Hopp b7944f
   * Don't consider "} else" a terminated line.
Karsten Hopp b7944f
   * Return the character terminating the line (ending char's have precedence if
Karsten Hopp b7944f
   * both apply in order to determine initializations).
Karsten Hopp b7944f
   */
Karsten Hopp b7944f
--- 5458,5468 ----
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  /*
Karsten Hopp b7944f
!  * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
Karsten Hopp b7944f
!  * '}'.
Karsten Hopp b7944f
   * Don't consider "} else" a terminated line.
Karsten Hopp b7944f
+  * Don't consider a line where there are unmatched opening braces before '}',
Karsten Hopp b7944f
+  * ';' or ',' a terminated line.
Karsten Hopp b7944f
   * Return the character terminating the line (ending char's have precedence if
Karsten Hopp b7944f
   * both apply in order to determine initializations).
Karsten Hopp b7944f
   */
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 5470,5475 ****
Karsten Hopp b7944f
--- 5473,5479 ----
Karsten Hopp b7944f
      int		incl_comma;	/* recognize a trailing comma */
Karsten Hopp b7944f
  {
Karsten Hopp b7944f
      char_u found_start = 0;
Karsten Hopp b7944f
+     unsigned n_open = 0;
Karsten Hopp b7944f
  
Karsten Hopp b7944f
      s = cin_skipcomment(s);
Karsten Hopp b7944f
  
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 5480,5489 ****
Karsten Hopp b7944f
      {
Karsten Hopp b7944f
  	/* skip over comments, "" strings and 'c'haracters */
Karsten Hopp b7944f
  	s = skip_string(cin_skipcomment(s));
Karsten Hopp b7944f
! 	if ((*s == ';' || (incl_open && *s == '{') || *s == '}'
Karsten Hopp b7944f
! 						 || (incl_comma && *s == ','))
Karsten Hopp b7944f
  		&& cin_nocode(s + 1))
Karsten Hopp b7944f
  	    return *s;
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  	if (*s)
Karsten Hopp b7944f
  	    s++;
Karsten Hopp b7944f
--- 5484,5502 ----
Karsten Hopp b7944f
      {
Karsten Hopp b7944f
  	/* skip over comments, "" strings and 'c'haracters */
Karsten Hopp b7944f
  	s = skip_string(cin_skipcomment(s));
Karsten Hopp b7944f
! 	if (*s == '}' && n_open > 0)
Karsten Hopp b7944f
! 	    --n_open;
Karsten Hopp b7944f
! 	if (n_open == 0
Karsten Hopp b7944f
! 		&& (*s == ';' || *s == '}' || (incl_comma && *s == ','))
Karsten Hopp b7944f
  		&& cin_nocode(s + 1))
Karsten Hopp b7944f
  	    return *s;
Karsten Hopp b7944f
+ 	else if (*s == '{')
Karsten Hopp b7944f
+ 	{
Karsten Hopp b7944f
+ 	    if (incl_open && cin_nocode(s + 1))
Karsten Hopp b7944f
+ 		return *s;
Karsten Hopp b7944f
+ 	    else
Karsten Hopp b7944f
+ 		++n_open;
Karsten Hopp b7944f
+ 	}
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  	if (*s)
Karsten Hopp b7944f
  	    s++;
Karsten Hopp b7944f
*** ../vim-7.3.177/src/testdir/test3.in	2011-04-28 13:01:59.000000000 +0200
Karsten Hopp b7944f
--- src/testdir/test3.in	2011-05-10 11:34:13.000000000 +0200
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 1344,1349 ****
Karsten Hopp b7944f
--- 1344,1365 ----
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
  STARTTEST
Karsten Hopp b7944f
+ :set cino&
Karsten Hopp b7944f
+ 2kdd=][
Karsten Hopp b7944f
+ ENDTEST
Karsten Hopp b7944f
+ 
Karsten Hopp b7944f
+ void func(void)
Karsten Hopp b7944f
+ {
Karsten Hopp b7944f
+ 	if(x==y)
Karsten Hopp b7944f
+ 		if(y==z)
Karsten Hopp b7944f
+ 			foo=1;
Karsten Hopp b7944f
+ 		else { bar=1;
Karsten Hopp b7944f
+ 			baz=2;
Karsten Hopp b7944f
+ 		}
Karsten Hopp b7944f
+ 	printf("Foo!\n");
Karsten Hopp b7944f
+ }
Karsten Hopp b7944f
+ 
Karsten Hopp b7944f
+ STARTTEST
Karsten Hopp b7944f
  :g/^STARTTEST/.,/^ENDTEST/d
Karsten Hopp b7944f
  :1;/start of AUTO/,$wq! test.out
Karsten Hopp b7944f
  ENDTEST
Karsten Hopp b7944f
*** ../vim-7.3.177/src/testdir/test3.ok	2011-04-28 13:01:59.000000000 +0200
Karsten Hopp b7944f
--- src/testdir/test3.ok	2011-05-10 11:34:13.000000000 +0200
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 1204,1206 ****
Karsten Hopp b7944f
--- 1204,1218 ----
Karsten Hopp b7944f
  {
Karsten Hopp b7944f
  }
Karsten Hopp b7944f
  
Karsten Hopp b7944f
+ 
Karsten Hopp b7944f
+ void func(void)
Karsten Hopp b7944f
+ {
Karsten Hopp b7944f
+ 	if(x==y)
Karsten Hopp b7944f
+ 		if(y==z)
Karsten Hopp b7944f
+ 			foo=1;
Karsten Hopp b7944f
+ 		else { bar=1;
Karsten Hopp b7944f
+ 			baz=2;
Karsten Hopp b7944f
+ 		}
Karsten Hopp b7944f
+ 	printf("Foo!\n");
Karsten Hopp b7944f
+ }
Karsten Hopp b7944f
+ 
Karsten Hopp b7944f
*** ../vim-7.3.177/src/version.c	2011-05-05 18:31:54.000000000 +0200
Karsten Hopp b7944f
--- src/version.c	2011-05-10 11:37:43.000000000 +0200
Karsten Hopp b7944f
***************
Karsten Hopp b7944f
*** 716,717 ****
Karsten Hopp b7944f
--- 716,719 ----
Karsten Hopp b7944f
  {   /* Add new patch number below this line */
Karsten Hopp b7944f
+ /**/
Karsten Hopp b7944f
+     178,
Karsten Hopp b7944f
  /**/
Karsten Hopp b7944f
Karsten Hopp b7944f
-- 
Karsten Hopp b7944f
hundred-and-one symptoms of being an internet addict:
Karsten Hopp b7944f
69. Yahoo welcomes you with your own start page
Karsten Hopp b7944f
Karsten Hopp b7944f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b7944f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b7944f
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp b7944f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///