Karsten Hopp b77dae
To: vim_dev@googlegroups.com
Karsten Hopp b77dae
Subject: Patch 7.3.380
Karsten Hopp b77dae
Fcc: outbox
Karsten Hopp b77dae
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b77dae
Mime-Version: 1.0
Karsten Hopp b77dae
Content-Type: text/plain; charset=UTF-8
Karsten Hopp b77dae
Content-Transfer-Encoding: 8bit
Karsten Hopp b77dae
------------
Karsten Hopp b77dae
Karsten Hopp b77dae
Patch 7.3.380
Karsten Hopp b77dae
Problem:    C-indenting wrong for a function header.
Karsten Hopp b77dae
Solution:   Skip to the start paren. (Lech Lorens)
Karsten Hopp b77dae
Files:	    src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
Karsten Hopp b77dae
Karsten Hopp b77dae
Karsten Hopp b77dae
*** ../vim-7.3.379/src/misc1.c	2011-12-14 20:05:17.000000000 +0100
Karsten Hopp b77dae
--- src/misc1.c	2011-12-14 20:16:43.000000000 +0100
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 4943,4949 ****
Karsten Hopp b77dae
  static int	cin_islinecomment __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_isterminated __ARGS((char_u *, int, int));
Karsten Hopp b77dae
  static int	cin_isinit __ARGS((void));
Karsten Hopp b77dae
! static int	cin_isfuncdecl __ARGS((char_u **, linenr_T));
Karsten Hopp b77dae
  static int	cin_isif __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_iselse __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_isdo __ARGS((char_u *));
Karsten Hopp b77dae
--- 4943,4949 ----
Karsten Hopp b77dae
  static int	cin_islinecomment __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_isterminated __ARGS((char_u *, int, int));
Karsten Hopp b77dae
  static int	cin_isinit __ARGS((void));
Karsten Hopp b77dae
! static int	cin_isfuncdecl __ARGS((char_u **, linenr_T, linenr_T, int, int));
Karsten Hopp b77dae
  static int	cin_isif __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_iselse __ARGS((char_u *));
Karsten Hopp b77dae
  static int	cin_isdo __ARGS((char_u *));
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 5585,5605 ****
Karsten Hopp b77dae
   * "sp" points to a string with the line.  When looking at other lines it must
Karsten Hopp b77dae
   * be restored to the line.  When it's NULL fetch lines here.
Karsten Hopp b77dae
   * "lnum" is where we start looking.
Karsten Hopp b77dae
   */
Karsten Hopp b77dae
      static int
Karsten Hopp b77dae
! cin_isfuncdecl(sp, first_lnum)
Karsten Hopp b77dae
      char_u	**sp;
Karsten Hopp b77dae
      linenr_T	first_lnum;
Karsten Hopp b77dae
  {
Karsten Hopp b77dae
      char_u	*s;
Karsten Hopp b77dae
      linenr_T	lnum = first_lnum;
Karsten Hopp b77dae
      int		retval = FALSE;
Karsten Hopp b77dae
  
Karsten Hopp b77dae
      if (sp == NULL)
Karsten Hopp b77dae
  	s = ml_get(lnum);
Karsten Hopp b77dae
      else
Karsten Hopp b77dae
  	s = *sp;
Karsten Hopp b77dae
  
Karsten Hopp b77dae
      /* Ignore line starting with #. */
Karsten Hopp b77dae
      if (cin_ispreproc(s))
Karsten Hopp b77dae
  	return FALSE;
Karsten Hopp b77dae
--- 5585,5621 ----
Karsten Hopp b77dae
   * "sp" points to a string with the line.  When looking at other lines it must
Karsten Hopp b77dae
   * be restored to the line.  When it's NULL fetch lines here.
Karsten Hopp b77dae
   * "lnum" is where we start looking.
Karsten Hopp b77dae
+  * "min_lnum" is the line before which we will not be looking.
Karsten Hopp b77dae
   */
Karsten Hopp b77dae
      static int
Karsten Hopp b77dae
! cin_isfuncdecl(sp, first_lnum, min_lnum, ind_maxparen, ind_maxcomment)
Karsten Hopp b77dae
      char_u	**sp;
Karsten Hopp b77dae
      linenr_T	first_lnum;
Karsten Hopp b77dae
+     linenr_T	min_lnum;
Karsten Hopp b77dae
+     int		ind_maxparen;
Karsten Hopp b77dae
+     int		ind_maxcomment;
Karsten Hopp b77dae
  {
Karsten Hopp b77dae
      char_u	*s;
Karsten Hopp b77dae
      linenr_T	lnum = first_lnum;
Karsten Hopp b77dae
      int		retval = FALSE;
Karsten Hopp b77dae
+     pos_T	*trypos;
Karsten Hopp b77dae
+     int		just_started = TRUE;
Karsten Hopp b77dae
  
Karsten Hopp b77dae
      if (sp == NULL)
Karsten Hopp b77dae
  	s = ml_get(lnum);
Karsten Hopp b77dae
      else
Karsten Hopp b77dae
  	s = *sp;
Karsten Hopp b77dae
  
Karsten Hopp b77dae
+     if (find_last_paren(s, '(', ')')
Karsten Hopp b77dae
+ 	&& (trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL)
Karsten Hopp b77dae
+     {
Karsten Hopp b77dae
+ 	lnum = trypos->lnum;
Karsten Hopp b77dae
+ 	if (lnum < min_lnum)
Karsten Hopp b77dae
+ 	    return FALSE;
Karsten Hopp b77dae
+ 
Karsten Hopp b77dae
+ 	s = ml_get(lnum);
Karsten Hopp b77dae
+     }
Karsten Hopp b77dae
+ 
Karsten Hopp b77dae
      /* Ignore line starting with #. */
Karsten Hopp b77dae
      if (cin_ispreproc(s))
Karsten Hopp b77dae
  	return FALSE;
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 5650,5662 ****
Karsten Hopp b77dae
  	    /* Require a comma at end of the line or a comma or ')' at the
Karsten Hopp b77dae
  	     * start of next line. */
Karsten Hopp b77dae
  	    s = skipwhite(s);
Karsten Hopp b77dae
! 	    if (!comma && *s != ',' && *s != ')')
Karsten Hopp b77dae
  		break;
Karsten Hopp b77dae
  	}
Karsten Hopp b77dae
  	else if (cin_iscomment(s))	/* ignore comments */
Karsten Hopp b77dae
  	    s = cin_skipcomment(s);
Karsten Hopp b77dae
  	else
Karsten Hopp b77dae
  	    ++s;
Karsten Hopp b77dae
      }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  done:
Karsten Hopp b77dae
--- 5666,5682 ----
Karsten Hopp b77dae
  	    /* Require a comma at end of the line or a comma or ')' at the
Karsten Hopp b77dae
  	     * start of next line. */
Karsten Hopp b77dae
  	    s = skipwhite(s);
Karsten Hopp b77dae
! 	    if (!just_started && (!comma && *s != ',' && *s != ')'))
Karsten Hopp b77dae
  		break;
Karsten Hopp b77dae
+ 	    just_started = FALSE;
Karsten Hopp b77dae
  	}
Karsten Hopp b77dae
  	else if (cin_iscomment(s))	/* ignore comments */
Karsten Hopp b77dae
  	    s = cin_skipcomment(s);
Karsten Hopp b77dae
  	else
Karsten Hopp b77dae
+ 	{
Karsten Hopp b77dae
  	    ++s;
Karsten Hopp b77dae
+ 	    just_started = FALSE;
Karsten Hopp b77dae
+ 	}
Karsten Hopp b77dae
      }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  done:
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 7158,7164 ****
Karsten Hopp b77dae
  			 * (it's a variable declaration).
Karsten Hopp b77dae
  			 */
Karsten Hopp b77dae
  			if (start_brace != BRACE_IN_COL0
Karsten Hopp b77dae
! 				|| !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
Karsten Hopp b77dae
  			{
Karsten Hopp b77dae
  			    /* if the line is terminated with another ','
Karsten Hopp b77dae
  			     * it is a continued variable initialization.
Karsten Hopp b77dae
--- 7178,7185 ----
Karsten Hopp b77dae
  			 * (it's a variable declaration).
Karsten Hopp b77dae
  			 */
Karsten Hopp b77dae
  			if (start_brace != BRACE_IN_COL0
Karsten Hopp b77dae
! 				|| !cin_isfuncdecl(&l, curwin->w_cursor.lnum,
Karsten Hopp b77dae
! 					     0, ind_maxparen, ind_maxcomment))
Karsten Hopp b77dae
  			{
Karsten Hopp b77dae
  			    /* if the line is terminated with another ','
Karsten Hopp b77dae
  			     * it is a continued variable initialization.
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 8019,8025 ****
Karsten Hopp b77dae
  		&& vim_strchr(theline, '}') == NULL
Karsten Hopp b77dae
  		&& !cin_ends_in(theline, (char_u *)":", NULL)
Karsten Hopp b77dae
  		&& !cin_ends_in(theline, (char_u *)",", NULL)
Karsten Hopp b77dae
! 		&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
Karsten Hopp b77dae
  		&& !cin_isterminated(theline, FALSE, TRUE))
Karsten Hopp b77dae
  	{
Karsten Hopp b77dae
  	    amount = ind_func_type;
Karsten Hopp b77dae
--- 8040,8048 ----
Karsten Hopp b77dae
  		&& vim_strchr(theline, '}') == NULL
Karsten Hopp b77dae
  		&& !cin_ends_in(theline, (char_u *)":", NULL)
Karsten Hopp b77dae
  		&& !cin_ends_in(theline, (char_u *)",", NULL)
Karsten Hopp b77dae
! 		&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
Karsten Hopp b77dae
! 				  cur_curpos.lnum + 1,
Karsten Hopp b77dae
! 				  ind_maxparen, ind_maxcomment)
Karsten Hopp b77dae
  		&& !cin_isterminated(theline, FALSE, TRUE))
Karsten Hopp b77dae
  	{
Karsten Hopp b77dae
  	    amount = ind_func_type;
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 8125,8131 ****
Karsten Hopp b77dae
  		 * If the line looks like a function declaration, and we're
Karsten Hopp b77dae
  		 * not in a comment, put it the left margin.
Karsten Hopp b77dae
  		 */
Karsten Hopp b77dae
! 		if (cin_isfuncdecl(NULL, cur_curpos.lnum))  /* XXX */
Karsten Hopp b77dae
  		    break;
Karsten Hopp b77dae
  		l = ml_get_curline();
Karsten Hopp b77dae
  
Karsten Hopp b77dae
--- 8148,8155 ----
Karsten Hopp b77dae
  		 * If the line looks like a function declaration, and we're
Karsten Hopp b77dae
  		 * not in a comment, put it the left margin.
Karsten Hopp b77dae
  		 */
Karsten Hopp b77dae
! 		if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0,
Karsten Hopp b77dae
! 				   ind_maxparen, ind_maxcomment))  /* XXX */
Karsten Hopp b77dae
  		    break;
Karsten Hopp b77dae
  		l = ml_get_curline();
Karsten Hopp b77dae
  
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 8173,8179 ****
Karsten Hopp b77dae
  		 * line (and the ones that follow) needs to be indented as
Karsten Hopp b77dae
  		 * parameters.
Karsten Hopp b77dae
  		 */
Karsten Hopp b77dae
! 		if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
Karsten Hopp b77dae
  		{
Karsten Hopp b77dae
  		    amount = ind_param;
Karsten Hopp b77dae
  		    break;
Karsten Hopp b77dae
--- 8197,8204 ----
Karsten Hopp b77dae
  		 * line (and the ones that follow) needs to be indented as
Karsten Hopp b77dae
  		 * parameters.
Karsten Hopp b77dae
  		 */
Karsten Hopp b77dae
! 		if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0,
Karsten Hopp b77dae
! 				   ind_maxparen, ind_maxcomment))
Karsten Hopp b77dae
  		{
Karsten Hopp b77dae
  		    amount = ind_param;
Karsten Hopp b77dae
  		    break;
Karsten Hopp b77dae
*** ../vim-7.3.379/src/testdir/test3.in	2011-12-14 20:05:17.000000000 +0100
Karsten Hopp b77dae
--- src/testdir/test3.in	2011-12-14 20:11:24.000000000 +0100
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 1429,1435 ****
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  STARTTEST
Karsten Hopp b77dae
  :set cino&
Karsten Hopp b77dae
! 2kdd=4][
Karsten Hopp b77dae
  ENDTEST
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  void func(void)
Karsten Hopp b77dae
--- 1429,1435 ----
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  STARTTEST
Karsten Hopp b77dae
  :set cino&
Karsten Hopp b77dae
! 2kdd=7][
Karsten Hopp b77dae
  ENDTEST
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  void func(void)
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 1478,1484 ****
Karsten Hopp b77dae
  	3, 4,
Karsten Hopp b77dae
  	5, 6};
Karsten Hopp b77dae
  
Karsten Hopp b77dae
! printf("Don't you dare indent this line incorrectly!\n);
Karsten Hopp b77dae
  }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  STARTTEST
Karsten Hopp b77dae
--- 1478,1506 ----
Karsten Hopp b77dae
  	3, 4,
Karsten Hopp b77dae
  	5, 6};
Karsten Hopp b77dae
  
Karsten Hopp b77dae
! printf("Don't you dare indent this line incorrectly!\n");
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! void
Karsten Hopp b77dae
! func4(a, b,
Karsten Hopp b77dae
! 		c)
Karsten Hopp b77dae
! int a;
Karsten Hopp b77dae
! int b;
Karsten Hopp b77dae
! int c;
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! void
Karsten Hopp b77dae
! func5(
Karsten Hopp b77dae
! 		int a,
Karsten Hopp b77dae
! 		int b)
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! void
Karsten Hopp b77dae
! func6(
Karsten Hopp b77dae
! 		int a)
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
  }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  STARTTEST
Karsten Hopp b77dae
*** ../vim-7.3.379/src/testdir/test3.ok	2011-12-14 20:05:17.000000000 +0100
Karsten Hopp b77dae
--- src/testdir/test3.ok	2011-12-14 20:11:24.000000000 +0100
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 1331,1337 ****
Karsten Hopp b77dae
  		3, 4,
Karsten Hopp b77dae
  		5, 6};
Karsten Hopp b77dae
  
Karsten Hopp b77dae
! 	printf("Don't you dare indent this line incorrectly!\n);
Karsten Hopp b77dae
  }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  
Karsten Hopp b77dae
--- 1331,1359 ----
Karsten Hopp b77dae
  		3, 4,
Karsten Hopp b77dae
  		5, 6};
Karsten Hopp b77dae
  
Karsten Hopp b77dae
! 	printf("Don't you dare indent this line incorrectly!\n");
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! 	void
Karsten Hopp b77dae
! func4(a, b,
Karsten Hopp b77dae
! 		c)
Karsten Hopp b77dae
! 	int a;
Karsten Hopp b77dae
! 	int b;
Karsten Hopp b77dae
! 	int c;
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! 	void
Karsten Hopp b77dae
! func5(
Karsten Hopp b77dae
! 		int a,
Karsten Hopp b77dae
! 		int b)
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
! }
Karsten Hopp b77dae
! 
Karsten Hopp b77dae
! 	void
Karsten Hopp b77dae
! func6(
Karsten Hopp b77dae
! 		int a)
Karsten Hopp b77dae
! {
Karsten Hopp b77dae
  }
Karsten Hopp b77dae
  
Karsten Hopp b77dae
  
Karsten Hopp b77dae
*** ../vim-7.3.379/src/version.c	2011-12-14 20:05:17.000000000 +0100
Karsten Hopp b77dae
--- src/version.c	2011-12-14 20:20:50.000000000 +0100
Karsten Hopp b77dae
***************
Karsten Hopp b77dae
*** 716,717 ****
Karsten Hopp b77dae
--- 716,719 ----
Karsten Hopp b77dae
  {   /* Add new patch number below this line */
Karsten Hopp b77dae
+ /**/
Karsten Hopp b77dae
+     380,
Karsten Hopp b77dae
  /**/
Karsten Hopp b77dae
Karsten Hopp b77dae
-- 
Karsten Hopp b77dae
"Intelligence has much less practical application than you'd think."
Karsten Hopp b77dae
		  -- Scott Adams, Dilbert.
Karsten Hopp b77dae
Karsten Hopp b77dae
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b77dae
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b77dae
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp b77dae
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///