home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.380 < prev    next >
Encoding:
Internet Message Format  |  2012-11-20  |  7.6 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.380
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.380
  11. Problem:    C-indenting wrong for a function header.
  12. Solution:   Skip to the start paren. (Lech Lorens)
  13. Files:        src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
  14.  
  15.  
  16. *** ../vim-7.3.379/src/misc1.c    2011-12-14 20:05:17.000000000 +0100
  17. --- src/misc1.c    2011-12-14 20:16:43.000000000 +0100
  18. ***************
  19. *** 4943,4949 ****
  20.   static int    cin_islinecomment __ARGS((char_u *));
  21.   static int    cin_isterminated __ARGS((char_u *, int, int));
  22.   static int    cin_isinit __ARGS((void));
  23. ! static int    cin_isfuncdecl __ARGS((char_u **, linenr_T));
  24.   static int    cin_isif __ARGS((char_u *));
  25.   static int    cin_iselse __ARGS((char_u *));
  26.   static int    cin_isdo __ARGS((char_u *));
  27. --- 4943,4949 ----
  28.   static int    cin_islinecomment __ARGS((char_u *));
  29.   static int    cin_isterminated __ARGS((char_u *, int, int));
  30.   static int    cin_isinit __ARGS((void));
  31. ! static int    cin_isfuncdecl __ARGS((char_u **, linenr_T, linenr_T, int, int));
  32.   static int    cin_isif __ARGS((char_u *));
  33.   static int    cin_iselse __ARGS((char_u *));
  34.   static int    cin_isdo __ARGS((char_u *));
  35. ***************
  36. *** 5585,5605 ****
  37.    * "sp" points to a string with the line.  When looking at other lines it must
  38.    * be restored to the line.  When it's NULL fetch lines here.
  39.    * "lnum" is where we start looking.
  40.    */
  41.       static int
  42. ! cin_isfuncdecl(sp, first_lnum)
  43.       char_u    **sp;
  44.       linenr_T    first_lnum;
  45.   {
  46.       char_u    *s;
  47.       linenr_T    lnum = first_lnum;
  48.       int        retval = FALSE;
  49.   
  50.       if (sp == NULL)
  51.       s = ml_get(lnum);
  52.       else
  53.       s = *sp;
  54.   
  55.       /* Ignore line starting with #. */
  56.       if (cin_ispreproc(s))
  57.       return FALSE;
  58. --- 5585,5621 ----
  59.    * "sp" points to a string with the line.  When looking at other lines it must
  60.    * be restored to the line.  When it's NULL fetch lines here.
  61.    * "lnum" is where we start looking.
  62. +  * "min_lnum" is the line before which we will not be looking.
  63.    */
  64.       static int
  65. ! cin_isfuncdecl(sp, first_lnum, min_lnum, ind_maxparen, ind_maxcomment)
  66.       char_u    **sp;
  67.       linenr_T    first_lnum;
  68. +     linenr_T    min_lnum;
  69. +     int        ind_maxparen;
  70. +     int        ind_maxcomment;
  71.   {
  72.       char_u    *s;
  73.       linenr_T    lnum = first_lnum;
  74.       int        retval = FALSE;
  75. +     pos_T    *trypos;
  76. +     int        just_started = TRUE;
  77.   
  78.       if (sp == NULL)
  79.       s = ml_get(lnum);
  80.       else
  81.       s = *sp;
  82.   
  83. +     if (find_last_paren(s, '(', ')')
  84. +     && (trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL)
  85. +     {
  86. +     lnum = trypos->lnum;
  87. +     if (lnum < min_lnum)
  88. +         return FALSE;
  89. +     s = ml_get(lnum);
  90. +     }
  91.       /* Ignore line starting with #. */
  92.       if (cin_ispreproc(s))
  93.       return FALSE;
  94. ***************
  95. *** 5650,5662 ****
  96.           /* Require a comma at end of the line or a comma or ')' at the
  97.            * start of next line. */
  98.           s = skipwhite(s);
  99. !         if (!comma && *s != ',' && *s != ')')
  100.           break;
  101.       }
  102.       else if (cin_iscomment(s))    /* ignore comments */
  103.           s = cin_skipcomment(s);
  104.       else
  105.           ++s;
  106.       }
  107.   
  108.   done:
  109. --- 5666,5682 ----
  110.           /* Require a comma at end of the line or a comma or ')' at the
  111.            * start of next line. */
  112.           s = skipwhite(s);
  113. !         if (!just_started && (!comma && *s != ',' && *s != ')'))
  114.           break;
  115. +         just_started = FALSE;
  116.       }
  117.       else if (cin_iscomment(s))    /* ignore comments */
  118.           s = cin_skipcomment(s);
  119.       else
  120. +     {
  121.           ++s;
  122. +         just_started = FALSE;
  123. +     }
  124.       }
  125.   
  126.   done:
  127. ***************
  128. *** 7158,7164 ****
  129.                * (it's a variable declaration).
  130.                */
  131.               if (start_brace != BRACE_IN_COL0
  132. !                 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
  133.               {
  134.                   /* if the line is terminated with another ','
  135.                    * it is a continued variable initialization.
  136. --- 7178,7185 ----
  137.                * (it's a variable declaration).
  138.                */
  139.               if (start_brace != BRACE_IN_COL0
  140. !                 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum,
  141. !                          0, ind_maxparen, ind_maxcomment))
  142.               {
  143.                   /* if the line is terminated with another ','
  144.                    * it is a continued variable initialization.
  145. ***************
  146. *** 8019,8025 ****
  147.           && vim_strchr(theline, '}') == NULL
  148.           && !cin_ends_in(theline, (char_u *)":", NULL)
  149.           && !cin_ends_in(theline, (char_u *)",", NULL)
  150. !         && cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
  151.           && !cin_isterminated(theline, FALSE, TRUE))
  152.       {
  153.           amount = ind_func_type;
  154. --- 8040,8048 ----
  155.           && vim_strchr(theline, '}') == NULL
  156.           && !cin_ends_in(theline, (char_u *)":", NULL)
  157.           && !cin_ends_in(theline, (char_u *)",", NULL)
  158. !         && cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
  159. !                   cur_curpos.lnum + 1,
  160. !                   ind_maxparen, ind_maxcomment)
  161.           && !cin_isterminated(theline, FALSE, TRUE))
  162.       {
  163.           amount = ind_func_type;
  164. ***************
  165. *** 8125,8131 ****
  166.            * If the line looks like a function declaration, and we're
  167.            * not in a comment, put it the left margin.
  168.            */
  169. !         if (cin_isfuncdecl(NULL, cur_curpos.lnum))  /* XXX */
  170.               break;
  171.           l = ml_get_curline();
  172.   
  173. --- 8148,8155 ----
  174.            * If the line looks like a function declaration, and we're
  175.            * not in a comment, put it the left margin.
  176.            */
  177. !         if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0,
  178. !                    ind_maxparen, ind_maxcomment))  /* XXX */
  179.               break;
  180.           l = ml_get_curline();
  181.   
  182. ***************
  183. *** 8173,8179 ****
  184.            * line (and the ones that follow) needs to be indented as
  185.            * parameters.
  186.            */
  187. !         if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
  188.           {
  189.               amount = ind_param;
  190.               break;
  191. --- 8197,8204 ----
  192.            * line (and the ones that follow) needs to be indented as
  193.            * parameters.
  194.            */
  195. !         if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0,
  196. !                    ind_maxparen, ind_maxcomment))
  197.           {
  198.               amount = ind_param;
  199.               break;
  200. *** ../vim-7.3.379/src/testdir/test3.in    2011-12-14 20:05:17.000000000 +0100
  201. --- src/testdir/test3.in    2011-12-14 20:11:24.000000000 +0100
  202. ***************
  203. *** 1429,1435 ****
  204.   
  205.   STARTTEST
  206.   :set cino&
  207. ! 2kdd=4][
  208.   ENDTEST
  209.   
  210.   void func(void)
  211. --- 1429,1435 ----
  212.   
  213.   STARTTEST
  214.   :set cino&
  215. ! 2kdd=7][
  216.   ENDTEST
  217.   
  218.   void func(void)
  219. ***************
  220. *** 1478,1484 ****
  221.       3, 4,
  222.       5, 6};
  223.   
  224. ! printf("Don't you dare indent this line incorrectly!\n);
  225.   }
  226.   
  227.   STARTTEST
  228. --- 1478,1506 ----
  229.       3, 4,
  230.       5, 6};
  231.   
  232. ! printf("Don't you dare indent this line incorrectly!\n");
  233. ! }
  234. ! void
  235. ! func4(a, b,
  236. !         c)
  237. ! int a;
  238. ! int b;
  239. ! int c;
  240. ! {
  241. ! }
  242. ! void
  243. ! func5(
  244. !         int a,
  245. !         int b)
  246. ! {
  247. ! }
  248. ! void
  249. ! func6(
  250. !         int a)
  251. ! {
  252.   }
  253.   
  254.   STARTTEST
  255. *** ../vim-7.3.379/src/testdir/test3.ok    2011-12-14 20:05:17.000000000 +0100
  256. --- src/testdir/test3.ok    2011-12-14 20:11:24.000000000 +0100
  257. ***************
  258. *** 1331,1337 ****
  259.           3, 4,
  260.           5, 6};
  261.   
  262. !     printf("Don't you dare indent this line incorrectly!\n);
  263.   }
  264.   
  265.   
  266. --- 1331,1359 ----
  267.           3, 4,
  268.           5, 6};
  269.   
  270. !     printf("Don't you dare indent this line incorrectly!\n");
  271. ! }
  272. !     void
  273. ! func4(a, b,
  274. !         c)
  275. !     int a;
  276. !     int b;
  277. !     int c;
  278. ! {
  279. ! }
  280. !     void
  281. ! func5(
  282. !         int a,
  283. !         int b)
  284. ! {
  285. ! }
  286. !     void
  287. ! func6(
  288. !         int a)
  289. ! {
  290.   }
  291.   
  292.   
  293. *** ../vim-7.3.379/src/version.c    2011-12-14 20:05:17.000000000 +0100
  294. --- src/version.c    2011-12-14 20:20:50.000000000 +0100
  295. ***************
  296. *** 716,717 ****
  297. --- 716,719 ----
  298.   {   /* Add new patch number below this line */
  299. + /**/
  300. +     380,
  301.   /**/
  302.  
  303. -- 
  304. "Intelligence has much less practical application than you'd think."
  305.           -- Scott Adams, Dilbert.
  306.  
  307.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  308. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  309. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  310.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  311.