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 / 6.2.504 < prev    next >
Encoding:
Internet Message Format  |  2004-04-25  |  62.5 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.504
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.2.504
  11. Problem:    Various problems with 'cindent', among which that a
  12.         list of variable declarations is not indented properly.
  13. Solution:   Fix the wrong indenting.  Improve indenting of C++ methods.
  14.         Add the 'i', 'b' and 'W' options to 'cinoptions'. (mostly by
  15.         Helmut Stiegler)
  16.         Improve indenting of preprocessor-continuation lines.
  17. Files:        runtime/doc/indent.txt, src/misc1.c, src/testdir/test3.in,
  18.         src/testdir/test3.ok
  19.  
  20.  
  21. *** ../vim-6.2.503/runtime/doc/indent.txt    Sun Jun  1 12:20:33 2003
  22. --- runtime/doc/indent.txt    Sun Apr 25 11:57:22 2004
  23. ***************
  24. *** 1,4 ****
  25. ! *indent.txt*    For Vim version 6.2.  Last change: 2003 May 04
  26.   
  27.   
  28.             VIM REFERENCE MANUAL    by Bram Moolenaar
  29. --- 1,4 ----
  30. ! *indent.txt*    For Vim version 6.2.  Last change: 2004 Apr 25
  31.   
  32.   
  33.             VIM REFERENCE MANUAL    by Bram Moolenaar
  34. ***************
  35. *** 228,234 ****
  36.                  a = a + 1;          b = b + 1;
  37.   <
  38.       lN    If N != 0 Vim will align with a case label instead of the
  39. !           statement after it.
  40.   
  41.           cino=                cino=l1 >
  42.               switch (a) {          switch (a) {
  43. --- 228,234 ----
  44.                  a = a + 1;          b = b + 1;
  45.   <
  46.       lN    If N != 0 Vim will align with a case label instead of the
  47. !           statement after it in the same line.
  48.   
  49.           cino=                cino=l1 >
  50.               switch (a) {          switch (a) {
  51. ***************
  52. *** 236,241 ****
  53. --- 236,256 ----
  54.                       break;          break;
  55.                   }          }
  56.   <
  57. +     bN    If N != 0 Vim will align a final "break" with the case label,
  58. +           so that case..break looks like a sort of block. (default: 0).
  59. +         cino=            cino=b1 >
  60. +           switch (x)          switch(x)
  61. +           {              {
  62. +               case 1:          case 1:
  63. +               a = b;          a = b;
  64. +               break;      break;
  65. +               default:          default:
  66. +               a = 0;          a = 0;
  67. +               break;      break;
  68. +           }              }
  69. + <
  70.       gN    Place C++ scope declarations N characters from the indent of the
  71.             block they are in.  (default 'shiftwidth').  A scope declaration
  72.             can be "public:", "protected:" or "private:".
  73. ***************
  74. *** 271,276 ****
  75. --- 286,304 ----
  76.                 int          int             int
  77.             func()          func()          func()
  78.   <
  79. +     iN    Indent C++ base class declarations and contructor
  80. +           initializations, if they start in a new line (otherwise they
  81. +           are aligned at the right side of the ':').
  82. +           (default 'shiftwidth').
  83. +         cino=              cino=i0 >
  84. +           class MyClass :        class MyClass :
  85. +               public BaseClass      public BaseClass
  86. +           {}                {}
  87. +           MyClass::MyClass() :        MyClass::MyClass() :
  88. +               BaseClass(3)        BaseClass(3)
  89. +           {}                {}
  90. + <
  91.       +N    Indent a continuation line (a line that spills onto the next) N
  92.             additional characters.  (default 'shiftwidth').
  93.   
  94. ***************
  95. *** 347,352 ****
  96. --- 375,394 ----
  97.                && (   c2        && (   c2
  98.                   || c3))            || c3))
  99.                 foo;            foo;
  100. + <
  101. +     WN    When in unclosed parentheses and N is non-zero and either
  102. +           using "(0" or "u0", respectively and the unclosed parentheses is
  103. +           the last non-white character in its line and it is not the
  104. +           closing parentheses, indent the following line N characters
  105. +           relative to the outer context (i.e. start of the line or the
  106. +           next unclosed parentheses). (default: 0).
  107. +         cino=(0               cino=(0,W4 >
  108. +           a_long_line(            a_long_line(
  109. +                   argument,        argument,
  110. +                   argument);    argument);
  111. +           a_short_line(argument,    a_short_line(argument,
  112. +                    argument);         argument);
  113.   <
  114.       mN    When N is non-zero, line up a line starting with a closing
  115.             parentheses with the first character of the line with the
  116. *** ../vim-6.2.503/src/misc1.c    Mon Apr 19 20:26:43 2004
  117. --- src/misc1.c    Mon Apr 26 18:58:23 2004
  118. ***************
  119. *** 4351,4370 ****
  120.   static char_u    *after_label __ARGS((char_u *l));
  121.   static int    get_indent_nolabel __ARGS((linenr_T lnum));
  122.   static int    skip_label __ARGS((linenr_T, char_u **pp, int ind_maxcomment));
  123.   static int    cin_ispreproc __ARGS((char_u *));
  124.   static int    cin_iscomment __ARGS((char_u *));
  125.   static int    cin_islinecomment __ARGS((char_u *));
  126. ! static int    cin_isterminated __ARGS((char_u *, int));
  127. ! static int    cin_isfuncdecl __ARGS((char_u *));
  128.   static int    cin_isif __ARGS((char_u *));
  129.   static int    cin_iselse __ARGS((char_u *));
  130.   static int    cin_isdo __ARGS((char_u *));
  131.   static int    cin_iswhileofdo __ARGS((char_u *, linenr_T, int));
  132. ! static int    cin_ends_in __ARGS((char_u *, char_u *));
  133.   static int    cin_skip2pos __ARGS((pos_T *trypos));
  134.   static pos_T    *find_start_brace __ARGS((int));
  135.   static pos_T    *find_match_paren __ARGS((int, int));
  136. ! static int    find_last_paren __ARGS((char_u *l));
  137.   static int    find_match __ARGS((int lookfor, linenr_T ourscope, int ind_maxparen, int ind_maxcomment));
  138.   
  139.   /*
  140. --- 4351,4377 ----
  141.   static char_u    *after_label __ARGS((char_u *l));
  142.   static int    get_indent_nolabel __ARGS((linenr_T lnum));
  143.   static int    skip_label __ARGS((linenr_T, char_u **pp, int ind_maxcomment));
  144. + static int    cin_first_id_amount __ARGS((void));
  145. + static int    cin_get_equal_amount __ARGS((linenr_T lnum));
  146.   static int    cin_ispreproc __ARGS((char_u *));
  147. + static int    cin_ispreproc_cont __ARGS((char_u **pp, linenr_T *lnump));
  148.   static int    cin_iscomment __ARGS((char_u *));
  149.   static int    cin_islinecomment __ARGS((char_u *));
  150. ! static int    cin_isterminated __ARGS((char_u *, int, int));
  151. ! static int    cin_isinit __ARGS((void));
  152. ! static int    cin_isfuncdecl __ARGS((char_u **, linenr_T));
  153.   static int    cin_isif __ARGS((char_u *));
  154.   static int    cin_iselse __ARGS((char_u *));
  155.   static int    cin_isdo __ARGS((char_u *));
  156.   static int    cin_iswhileofdo __ARGS((char_u *, linenr_T, int));
  157. ! static int    cin_isbreak __ARGS((char_u *));
  158. ! static int    cin_is_cpp_baseclass __ARGS((char_u *line, colnr_T *col));
  159. ! static int    cin_ends_in __ARGS((char_u *, char_u *, char_u *));
  160.   static int    cin_skip2pos __ARGS((pos_T *trypos));
  161.   static pos_T    *find_start_brace __ARGS((int));
  162.   static pos_T    *find_match_paren __ARGS((int, int));
  163. ! static int    corr_ind_maxparen __ARGS((int ind_maxparen, pos_T *startpos));
  164. ! static int    find_last_paren __ARGS((char_u *l, int start, int end));
  165.   static int    find_match __ARGS((int lookfor, linenr_T ourscope, int ind_maxparen, int ind_maxcomment));
  166.   
  167.   /*
  168. ***************
  169. *** 4503,4509 ****
  170.           continue;
  171.   
  172.           curwin->w_cursor = cursor_save;
  173. !         if (cin_isterminated(line, TRUE)
  174.               || cin_isscopedecl(line)
  175.               || cin_iscase(line)
  176.               || (cin_islabel_skip(&line) && cin_nocode(line)))
  177. --- 4510,4516 ----
  178.           continue;
  179.   
  180.           curwin->w_cursor = cursor_save;
  181. !         if (cin_isterminated(line, TRUE, FALSE)
  182.               || cin_isscopedecl(line)
  183.               || cin_iscase(line)
  184.               || (cin_islabel_skip(&line) && cin_nocode(line)))
  185. ***************
  186. *** 4517,4522 ****
  187. --- 4524,4550 ----
  188.   }
  189.   
  190.   /*
  191. +  * Recognize structure initialization and enumerations.
  192. +  * Q&D-Implementation:
  193. +  * check for "=" at end or "enum" at beginning of line.
  194. +  */
  195. +     int
  196. + cin_isinit(void)
  197. + {
  198. +     char_u    *s;
  199. +     s = cin_skipcomment(ml_get_curline());
  200. +     if (STRNCMP(s, "enum", 4) == 0 && !vim_isIDc(s[4]))
  201. +     return TRUE;
  202. +     if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
  203. +     return TRUE;
  204. +     return FALSE;
  205. + }
  206. + /*
  207.    * Recognize a switch label: "case .*:" or "default:".
  208.    */
  209.        int
  210. ***************
  211. *** 4677,4682 ****
  212. --- 4705,4808 ----
  213.   }
  214.   
  215.   /*
  216. +  * Return the indent of the first variable name after a type in a declaration.
  217. +  *  int        a,            indent of "a"
  218. +  *  static struct foo    b,    indent of "b"
  219. +  *  enum bla    c,        indent of "c"
  220. +  * Returns zero when it doesn't look like a declaration.
  221. +  */
  222. +     static int
  223. + cin_first_id_amount()
  224. + {
  225. +     char_u    *line, *p, *s;
  226. +     int        len;
  227. +     pos_T    fp;
  228. +     colnr_T    col;
  229. +     line = ml_get_curline();
  230. +     p = skipwhite(line);
  231. +     len = skiptowhite(p) - p;
  232. +     if (len == 6 && STRNCMP(p, "static", 6) == 0)
  233. +     {
  234. +     p = skipwhite(p + 6);
  235. +     len = skiptowhite(p) - p;
  236. +     }
  237. +     if (len == 6 && STRNCMP(p, "struct", 6) == 0)
  238. +     p = skipwhite(p + 6);
  239. +     else if (len == 4 && STRNCMP(p, "enum", 4) == 0)
  240. +     p = skipwhite(p + 4);
  241. +     else if ((len == 8 && STRNCMP(p, "unsigned", 8) == 0)
  242. +         || (len == 6 && STRNCMP(p, "signed", 6) == 0))
  243. +     {
  244. +     s = skipwhite(p + len);
  245. +     if ((STRNCMP(s, "int", 3) == 0 && vim_iswhite(s[3]))
  246. +         || (STRNCMP(s, "long", 4) == 0 && vim_iswhite(s[4]))
  247. +         || (STRNCMP(s, "short", 5) == 0 && vim_iswhite(s[5]))
  248. +         || (STRNCMP(s, "char", 4) == 0 && vim_iswhite(s[4])))
  249. +         p = s;
  250. +     }
  251. +     for (len = 0; vim_isIDc(p[len]); ++len)
  252. +     ;
  253. +     if (len == 0 || !vim_iswhite(p[len]) || cin_nocode(p))
  254. +     return 0;
  255. +     p = skipwhite(p + len);
  256. +     fp.lnum = curwin->w_cursor.lnum;
  257. +     fp.col = (colnr_T)(p - line);
  258. +     getvcol(curwin, &fp, &col, NULL, NULL);
  259. +     return (int)col;
  260. + }
  261. + /*
  262. +  * Return the indent of the first non-blank after an equal sign.
  263. +  *       char *foo = "here";
  264. +  * Return zero if no (useful) equal sign found.
  265. +  * Return -1 if the line above "lnum" ends in a backslash.
  266. +  *      foo = "asdf\
  267. +  *           asdf\
  268. +  *           here";
  269. +  */
  270. +     static int
  271. + cin_get_equal_amount(lnum)
  272. +     linenr_T    lnum;
  273. + {
  274. +     char_u    *line;
  275. +     char_u    *s;
  276. +     colnr_T    col;
  277. +     pos_T    fp;
  278. +     if (lnum > 1)
  279. +     {
  280. +     line = ml_get(lnum - 1);
  281. +     if (*line != NUL && line[STRLEN(line) - 1] == '\\')
  282. +         return -1;
  283. +     }
  284. +     line = s = ml_get(lnum);
  285. +     while (*s != NUL && vim_strchr((char_u *)"=;{}\"'", *s) == NULL)
  286. +     {
  287. +     if (cin_iscomment(s))    /* ignore comments */
  288. +         s = cin_skipcomment(s);
  289. +     else
  290. +         ++s;
  291. +     }
  292. +     if (*s != '=')
  293. +     return 0;
  294. +     s = skipwhite(s + 1);
  295. +     if (cin_nocode(s))
  296. +     return 0;
  297. +     if (*s == '"')    /* nice alignment for continued strings */
  298. +     ++s;
  299. +     fp.lnum = lnum;
  300. +     fp.col = (colnr_T)(s - line);
  301. +     getvcol(curwin, &fp, &col, NULL, NULL);
  302. +     return (int)col;
  303. + }
  304. + /*
  305.    * Recognize a preprocessor statement: Any line that starts with '#'.
  306.    */
  307.       static int
  308. ***************
  309. *** 4690,4695 ****
  310. --- 4816,4855 ----
  311.   }
  312.   
  313.   /*
  314. +  * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
  315. +  * continuation line of a preprocessor statement.  Decrease "*lnump" to the
  316. +  * start and return the line in "*pp".
  317. +  */
  318. +     static int
  319. + cin_ispreproc_cont(pp, lnump)
  320. +     char_u    **pp;
  321. +     linenr_T    *lnump;
  322. + {
  323. +     char_u    *line = *pp;
  324. +     linenr_T    lnum = *lnump;
  325. +     int        retval = FALSE;
  326. +     while (1)
  327. +     {
  328. +     if (cin_ispreproc(line))
  329. +     {
  330. +         retval = TRUE;
  331. +         *lnump = lnum;
  332. +         break;
  333. +     }
  334. +     if (lnum == 1)
  335. +         break;
  336. +     line = ml_get(--lnum);
  337. +     if (*line == NUL || line[STRLEN(line) - 1] != '\\')
  338. +         break;
  339. +     }
  340. +     if (lnum != *lnump)
  341. +     *pp = ml_get(*lnump);
  342. +     return retval;
  343. + }
  344. + /*
  345.    * Recognize the start of a C or C++ comment.
  346.    */
  347.       static int
  348. ***************
  349. *** 4712,4752 ****
  350.   /*
  351.    * Recognize a line that starts with '{' or '}', or ends with ';', '{' or '}'.
  352.    * Don't consider "} else" a terminated line.
  353. !  * Also consider a line terminated if it ends in ','.  This is not 100%
  354. !  * correct, but this mostly means we are in initializations and then it's OK.
  355.    */
  356.       static int
  357. ! cin_isterminated(s, incl_open)
  358.       char_u    *s;
  359.       int        incl_open;    /* include '{' at the end as terminator */
  360.   {
  361.       s = cin_skipcomment(s);
  362.   
  363.       if (*s == '{' || (*s == '}' && !cin_iselse(s)))
  364. !     return TRUE;
  365.   
  366.       while (*s)
  367.       {
  368.       /* skip over comments, "" strings and 'c'haracters */
  369.       s = skip_string(cin_skipcomment(s));
  370. !     if ((*s == ';' || (incl_open && *s == '{') || *s == '}' || *s == ',')
  371. !                              && cin_nocode(s + 1))
  372. !         return TRUE;
  373.       if (*s)
  374.           s++;
  375.       }
  376. !     return FALSE;
  377.   }
  378.   
  379.   /*
  380.    * Recognize the basic picture of a function declaration -- it needs to
  381.    * have an open paren somewhere and a close paren at the end of the line and
  382.    * no semicolons anywhere.
  383.    */
  384.       static int
  385. ! cin_isfuncdecl(s)
  386. !     char_u *s;
  387.   {
  388.       while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
  389.       {
  390.       if (cin_iscomment(s))    /* ignore comments */
  391. --- 4872,4931 ----
  392.   /*
  393.    * Recognize a line that starts with '{' or '}', or ends with ';', '{' or '}'.
  394.    * Don't consider "} else" a terminated line.
  395. !  * Return the character terminating the line (ending char's have precedence if
  396. !  * both apply in order to determine initializations).
  397.    */
  398.       static int
  399. ! cin_isterminated(s, incl_open, incl_comma)
  400.       char_u    *s;
  401.       int        incl_open;    /* include '{' at the end as terminator */
  402. +     int        incl_comma;    /* recognize a trailing comma */
  403.   {
  404. +     char_u found_start = 0;
  405.       s = cin_skipcomment(s);
  406.   
  407.       if (*s == '{' || (*s == '}' && !cin_iselse(s)))
  408. !     found_start = *s;
  409.   
  410.       while (*s)
  411.       {
  412.       /* skip over comments, "" strings and 'c'haracters */
  413.       s = skip_string(cin_skipcomment(s));
  414. !     if ((*s == ';' || (incl_open && *s == '{') || *s == '}'
  415. !                          || (incl_comma && *s == ','))
  416. !         && cin_nocode(s + 1))
  417. !         return *s;
  418.       if (*s)
  419.           s++;
  420.       }
  421. !     return found_start;
  422.   }
  423.   
  424.   /*
  425.    * Recognize the basic picture of a function declaration -- it needs to
  426.    * have an open paren somewhere and a close paren at the end of the line and
  427.    * no semicolons anywhere.
  428. +  * When a line ends in a comma we continue looking in the next line.
  429. +  * "sp" points to a string with the line.  When looking at other lines it must
  430. +  * be restored to the line.  When it's NULL fetch lines here.
  431. +  * "lnum" is where we start looking.
  432.    */
  433.       static int
  434. ! cin_isfuncdecl(sp, first_lnum)
  435. !     char_u    **sp;
  436. !     linenr_T    first_lnum;
  437.   {
  438. +     char_u    *s;
  439. +     linenr_T    lnum = first_lnum;
  440. +     int        retval = FALSE;
  441. +     if (sp == NULL)
  442. +     s = ml_get(lnum);
  443. +     else
  444. +     s = *sp;
  445.       while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
  446.       {
  447.       if (cin_iscomment(s))    /* ignore comments */
  448. ***************
  449. *** 4760,4772 ****
  450.       while (*s && *s != ';' && *s != '\'' && *s != '"')
  451.       {
  452.       if (*s == ')' && cin_nocode(s + 1))
  453. !         return TRUE;
  454. !     if (cin_iscomment(s))    /* ignore comments */
  455.           s = cin_skipcomment(s);
  456.       else
  457.           ++s;
  458.       }
  459. !     return FALSE;
  460.   }
  461.   
  462.       static int
  463. --- 4939,4975 ----
  464.       while (*s && *s != ';' && *s != '\'' && *s != '"')
  465.       {
  466.       if (*s == ')' && cin_nocode(s + 1))
  467. !     {
  468. !         /* ')' at the end: may have found a match
  469. !          * Check for he previous line not to end in a backslash:
  470. !          *       #if defined(x) && \
  471. !          *         defined(y)
  472. !          */
  473. !         lnum = first_lnum - 1;
  474. !         s = ml_get(lnum);
  475. !         if (*s == NUL || s[STRLEN(s) - 1] != '\\')
  476. !         retval = TRUE;
  477. !         goto done;
  478. !     }
  479. !     if (*s == ',' && cin_nocode(s + 1))
  480. !     {
  481. !         /* ',' at the end: continue looking in the next line */
  482. !         if (lnum >= curbuf->b_ml.ml_line_count)
  483. !         break;
  484. !         s = ml_get(++lnum);
  485. !     }
  486. !     else if (cin_iscomment(s))    /* ignore comments */
  487.           s = cin_skipcomment(s);
  488.       else
  489.           ++s;
  490.       }
  491. ! done:
  492. !     if (lnum != first_lnum && sp != NULL)
  493. !     *sp = ml_get(first_lnum);
  494. !     return retval;
  495.   }
  496.   
  497.       static int
  498. ***************
  499. *** 4829,4842 ****
  500.       return retval;
  501.   }
  502.   
  503.   /*
  504.    * Return TRUE if string "s" ends with the string "find", possibly followed by
  505.    * white space and comments.  Skip strings and comments.
  506.    */
  507.       static int
  508. ! cin_ends_in(s, find)
  509.       char_u    *s;
  510.       char_u    *find;
  511.   {
  512.       char_u    *p = s;
  513.       char_u    *r;
  514. --- 5032,5150 ----
  515.       return retval;
  516.   }
  517.   
  518. +     static int
  519. + cin_isbreak(p)
  520. +     char_u  *p;
  521. + {
  522. +     return (STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]));
  523. + }
  524. + /* Find the position of a C++ base-class declaration or
  525. +  * constructor-initialization. eg:
  526. +  *
  527. +  * class MyClass :
  528. +  *    baseClass        <-- here
  529. +  * class MyClass : public baseClass,
  530. +  *    anotherBaseClass    <-- here (should probably lineup ??)
  531. +  * MyClass::MyClass(...) :
  532. +  *    baseClass(...)        <-- here (constructor-initialization)
  533. +  */
  534. +     static int
  535. + cin_is_cpp_baseclass(line, col)
  536. +     char_u    *line;
  537. +     colnr_T    *col;
  538. + {
  539. +     char_u    *s;
  540. +     int        class_or_struct, lookfor_ctor_init, cpp_base_class;
  541. +     *col = 0;
  542. +     s = cin_skipcomment(line);
  543. +     if (*s == NUL)
  544. +     return FALSE;
  545. +     cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
  546. +     while(*s != NUL)
  547. +     {
  548. +     if (s[0] == ':')
  549. +     {
  550. +         if (s[1] == ':')
  551. +         {
  552. +         /* skip double colon. It can't be a constructor
  553. +          * initialization any more */
  554. +         lookfor_ctor_init = FALSE;
  555. +         s = cin_skipcomment(s + 2);
  556. +         }
  557. +         else if (lookfor_ctor_init || class_or_struct)
  558. +         {
  559. +         /* we have something found, that looks like the start of
  560. +          * cpp-base-class-declaration or contructor-initialization */
  561. +         cpp_base_class = TRUE;
  562. +         lookfor_ctor_init = class_or_struct = FALSE;
  563. +         *col = 0;
  564. +         s = cin_skipcomment(s + 1);
  565. +         }
  566. +         else
  567. +         s = cin_skipcomment(s + 1);
  568. +     }
  569. +     else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
  570. +         || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6])))
  571. +     {
  572. +         class_or_struct = TRUE;
  573. +         lookfor_ctor_init = FALSE;
  574. +         if (*s == 'c')
  575. +         s = cin_skipcomment(s + 5);
  576. +         else
  577. +         s = cin_skipcomment(s + 6);
  578. +     }
  579. +     else
  580. +     {
  581. +         if (s[0] == '{' || s[0] == '}' || s[0] == ';')
  582. +         {
  583. +         cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
  584. +         }
  585. +         else if (s[0] == ')')
  586. +         {
  587. +         /* Constructor-initialization is assumed if we come across
  588. +          * something like "):" */
  589. +         class_or_struct = FALSE;
  590. +         lookfor_ctor_init = TRUE;
  591. +         }
  592. +         else if (!vim_isIDc(s[0]))
  593. +         {
  594. +         /* if it is not an identifier, we are wrong */
  595. +         class_or_struct = FALSE;
  596. +         lookfor_ctor_init = FALSE;
  597. +         }
  598. +         else if (*col == 0)
  599. +         {
  600. +         /* it can't be a constructor-initialization any more */
  601. +         lookfor_ctor_init = FALSE;
  602. +         /* the first statement starts here: lineup with this one... */
  603. +         if (cpp_base_class && *col == 0)
  604. +             *col = (colnr_T)(s - line);
  605. +         }
  606. +         s = cin_skipcomment(s + 1);
  607. +     }
  608. +     }
  609. +     return cpp_base_class;
  610. + }
  611.   /*
  612.    * Return TRUE if string "s" ends with the string "find", possibly followed by
  613.    * white space and comments.  Skip strings and comments.
  614. +  * Ignore "ignore" after "find" if it's not NULL.
  615.    */
  616.       static int
  617. ! cin_ends_in(s, find, ignore)
  618.       char_u    *s;
  619.       char_u    *find;
  620. +     char_u    *ignore;
  621.   {
  622.       char_u    *p = s;
  623.       char_u    *r;
  624. ***************
  625. *** 4848,4854 ****
  626.       if (STRNCMP(p, find, len) == 0)
  627.       {
  628.           r = skipwhite(p + len);
  629. !         if (*r == NUL || cin_iscomment(r))
  630.           return TRUE;
  631.       }
  632.       if (*p != NUL)
  633. --- 5156,5164 ----
  634.       if (STRNCMP(p, find, len) == 0)
  635.       {
  636.           r = skipwhite(p + len);
  637. !         if (ignore != NULL && STRNCMP(r, ignore, STRLEN(ignore)) == 0)
  638. !         r = skipwhite(r + STRLEN(ignore));
  639. !         if (cin_nocode(r))
  640.           return TRUE;
  641.       }
  642.       if (*p != NUL)
  643. ***************
  644. *** 4951,4974 ****
  645.   }
  646.   
  647.   /*
  648. !  * Set w_cursor.col to the column number of the last ')' in line "l".
  649.    */
  650.       static int
  651. ! find_last_paren(l)
  652. !     char_u *l;
  653.   {
  654. !     int        i;
  655. !     int        retval = FALSE;
  656.   
  657.       curwin->w_cursor.col = 0;            /* default is start of line */
  658.   
  659.       for (i = 0; l[i]; i++)
  660.       {
  661.       i = (int)(skip_string(l + i) - l);    /* ignore parens in quotes */
  662. !     if (l[i] == ')')
  663.       {
  664. !         curwin->w_cursor.col = i;
  665. !         retval = TRUE;
  666.       }
  667.       }
  668.       return retval;
  669. --- 5261,5313 ----
  670.   }
  671.   
  672.   /*
  673. !  * Return ind_maxparen corrected for the difference in line number between the
  674. !  * cursor position and "startpos".  This makes sure that searching for a
  675. !  * matching paren above the cursor line doesn't find a match because of
  676. !  * looking a few lines further.
  677.    */
  678.       static int
  679. ! corr_ind_maxparen(ind_maxparen, startpos)
  680. !     int        ind_maxparen;
  681. !     pos_T    *startpos;
  682.   {
  683. !     long    n = (long)startpos->lnum - (long)curwin->w_cursor.lnum;
  684. !     if (n > 0 && n < ind_maxparen / 2)
  685. !     return ind_maxparen - (int)n;
  686. !     return ind_maxparen;
  687. ! }
  688. ! /*
  689. !  * Set w_cursor.col to the column number of the last unmatched ')' or '{' in
  690. !  * line "l".
  691. !  */
  692. !     static int
  693. ! find_last_paren(l, start, end)
  694. !     char_u    *l;
  695. !     int        start, end;
  696. ! {
  697. !     int        i;
  698. !     int        retval = FALSE;
  699. !     int        open_count = 0;
  700.   
  701.       curwin->w_cursor.col = 0;            /* default is start of line */
  702.   
  703.       for (i = 0; l[i]; i++)
  704.       {
  705. +     i = (int)(cin_skipcomment(l + i) - l); /* ignore parens in comments */
  706.       i = (int)(skip_string(l + i) - l);    /* ignore parens in quotes */
  707. !     if (l[i] == start)
  708. !         ++open_count;
  709. !     else if (l[i] == end)
  710.       {
  711. !         if (open_count > 0)
  712. !         --open_count;
  713. !         else
  714. !         {
  715. !         curwin->w_cursor.col = i;
  716. !         retval = TRUE;
  717. !         }
  718.       }
  719.       }
  720.       return retval;
  721. ***************
  722. *** 5030,5035 ****
  723. --- 5369,5379 ----
  724.       int ind_case_code = curbuf->b_p_sw;
  725.   
  726.       /*
  727. +      * lineup break at end of case in switch() with case label
  728. +      */
  729. +     int ind_case_break = 0;
  730. +     /*
  731.        * spaces from the class declaration indent a scope declaration label
  732.        * should be located
  733.        */
  734. ***************
  735. *** 5051,5056 ****
  736. --- 5395,5406 ----
  737.       int ind_func_type = curbuf->b_p_sw;
  738.   
  739.       /*
  740. +      * amount a cpp base class declaration or constructor initialization
  741. +      * should be indented
  742. +      */
  743. +     int ind_cpp_baseclass = curbuf->b_p_sw;
  744. +     /*
  745.        * additional spaces beyond the prevailing indent a continuation line
  746.        * should be located
  747.        */
  748. ***************
  749. *** 5074,5079 ****
  750. --- 5424,5436 ----
  751.       int ind_unclosed_noignore = 0;
  752.   
  753.       /*
  754. +      * If the opening paren is the last nonwhite character on the line, and
  755. +      * ind_unclosed_wrapped is nonzero, use this indent relative to the outer
  756. +      * context (for very long lines).
  757. +      */
  758. +     int ind_unclosed_wrapped = 0;
  759. +     /*
  760.        * suppress ignoring white space when lining up with the character after
  761.        * an unclosed parentheses.
  762.        */
  763. ***************
  764. *** 5139,5145 ****
  765. --- 5496,5504 ----
  766.       linenr_T    ourscope;
  767.       char_u    *l;
  768.       char_u    *look;
  769. +     char_u    terminated;
  770.       int        lookfor;
  771. + #define LOOKFOR_INITIAL        0
  772.   #define LOOKFOR_IF        1
  773.   #define LOOKFOR_DO        2
  774.   #define LOOKFOR_CASE        3
  775. ***************
  776. *** 5147,5152 ****
  777. --- 5506,5515 ----
  778.   #define LOOKFOR_TERM        5
  779.   #define LOOKFOR_UNTERM        6
  780.   #define LOOKFOR_SCOPEDECL    7
  781. + #define LOOKFOR_NOBREAK        8
  782. + #define LOOKFOR_CPP_BASECLASS    9
  783. + #define LOOKFOR_ENUM_OR_INIT    10
  784.       int        whilelevel;
  785.       linenr_T    lnum;
  786.       char_u    *options;
  787. ***************
  788. *** 5154,5159 ****
  789. --- 5517,5524 ----
  790.       int        divider;
  791.       int        n;
  792.       int        iscase;
  793. +     int        lookfor_break;
  794. +     int        cont_amount = 0;    /* amount for continuation line */
  795.   
  796.       for (options = curbuf->b_p_cino; *options; )
  797.       {
  798. ***************
  799. *** 5201,5215 ****
  800. --- 5566,5583 ----
  801.           case '^': ind_open_left_imag = n; break;
  802.           case ':': ind_case = n; break;
  803.           case '=': ind_case_code = n; break;
  804. +         case 'b': ind_case_break = n; break;
  805.           case 'p': ind_param = n; break;
  806.           case 't': ind_func_type = n; break;
  807.           case '/': ind_comment = n; break;
  808.           case 'c': ind_in_comment = n; break;
  809.           case 'C': ind_in_comment2 = n; break;
  810. +         case 'i': ind_cpp_baseclass = n; break;
  811.           case '+': ind_continuation = n; break;
  812.           case '(': ind_unclosed = n; break;
  813.           case 'u': ind_unclosed2 = n; break;
  814.           case 'U': ind_unclosed_noignore = n; break;
  815. +         case 'W': ind_unclosed_wrapped = n; break;
  816.           case 'w': ind_unclosed_whiteok = n; break;
  817.           case 'm': ind_matching_paren = n; break;
  818.           case ')': ind_maxparen = n; break;
  819. ***************
  820. *** 5454,5487 ****
  821.        * a previous non-empty line that matches the same paren.
  822.        */
  823.       amount = -1;
  824.       our_paren_pos = *trypos;
  825. !     if (theline[0] != ')')
  826.       {
  827. !         for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum)
  828. !         {
  829. !         l = skipwhite(ml_get(lnum));
  830. !         if (cin_nocode(l))        /* skip comment lines */
  831. !             continue;
  832. !         if (cin_ispreproc(l))        /* ignore #defines, #if, etc. */
  833. !             continue;
  834. !         curwin->w_cursor.lnum = lnum;
  835.   
  836. !         /* Skip a comment. XXX */
  837. !         if ((trypos = find_start_comment(ind_maxcomment)) != NULL)
  838. !         {
  839. !             lnum = trypos->lnum + 1;
  840. !             continue;
  841. !         }
  842.   
  843. !         /* XXX */
  844. !         if ((trypos = find_match_paren(ind_maxparen,
  845. !                            ind_maxcomment)) != NULL &&
  846. !                      trypos->lnum == our_paren_pos.lnum &&
  847. !                          trypos->col == our_paren_pos.col)
  848. !         {
  849.               amount = get_indent_lnum(lnum);    /* XXX */
  850. !             break;
  851. !         }
  852.           }
  853.       }
  854.   
  855. --- 5822,5861 ----
  856.        * a previous non-empty line that matches the same paren.
  857.        */
  858.       amount = -1;
  859. +     cur_amount = MAXCOL;
  860.       our_paren_pos = *trypos;
  861. !     for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum)
  862.       {
  863. !         l = skipwhite(ml_get(lnum));
  864. !         if (cin_nocode(l))        /* skip comment lines */
  865. !         continue;
  866. !         if (cin_ispreproc_cont(&l, &lnum))    /* ignore #defines, #if, etc. */
  867. !         continue;
  868. !         curwin->w_cursor.lnum = lnum;
  869.   
  870. !         /* Skip a comment. XXX */
  871. !         if ((trypos = find_start_comment(ind_maxcomment)) != NULL)
  872. !         {
  873. !         lnum = trypos->lnum + 1;
  874. !         continue;
  875. !         }
  876.   
  877. !         /* XXX */
  878. !         if ((trypos = find_match_paren(
  879. !                 corr_ind_maxparen(ind_maxparen, &cur_curpos),
  880. !                               ind_maxcomment)) != NULL
  881. !             && trypos->lnum == our_paren_pos.lnum
  882. !             && trypos->col == our_paren_pos.col)
  883. !         {
  884.               amount = get_indent_lnum(lnum);    /* XXX */
  885. !             if (theline[0] == ')')
  886. !             {
  887. !             if (our_paren_pos.lnum != lnum && cur_amount > amount)
  888. !                 cur_amount = amount;
  889. !             amount = -1;
  890. !             }
  891. !         break;
  892.           }
  893.       }
  894.   
  895. ***************
  896. *** 5493,5514 ****
  897.       if (amount == -1)
  898.       {
  899.           amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment);
  900. -         cur_amount = MAXCOL;
  901.           if (theline[0] == ')' || ind_unclosed == 0
  902.                  || (!ind_unclosed_noignore && *skipwhite(look) == '('))
  903.           {
  904.           /*
  905.            * If we're looking at a close paren, line up right there;
  906.            * otherwise, line up with the next (non-white) character.
  907.            */
  908.           if (theline[0] != ')')
  909.           {
  910. !             if (ind_unclosed_whiteok)
  911.               our_paren_pos.col++;
  912.               else
  913.               {
  914.               col = our_paren_pos.col + 1;
  915. -             l = ml_get(our_paren_pos.lnum);
  916.               while (vim_iswhite(l[col]))
  917.                   col++;
  918.               if (l[col] != NUL)    /* In case of trailing space */
  919. --- 5867,5917 ----
  920.       if (amount == -1)
  921.       {
  922.           amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment);
  923.           if (theline[0] == ')' || ind_unclosed == 0
  924.                  || (!ind_unclosed_noignore && *skipwhite(look) == '('))
  925.           {
  926.           /*
  927.            * If we're looking at a close paren, line up right there;
  928.            * otherwise, line up with the next (non-white) character.
  929. +          * When ind_unclosed_wrapped is set and the matching paren is
  930. +          * the last nonwhite character of the line, use either the
  931. +          * indent of the current line or the indentation of the next
  932. +          * outer paren and add ind_unclosed_wrapped (for very long
  933. +          * lines).
  934.            */
  935.           if (theline[0] != ')')
  936.           {
  937. !             cur_amount = MAXCOL;
  938. !             l = ml_get(our_paren_pos.lnum);
  939. !             if (ind_unclosed_wrapped
  940. !                        && cin_ends_in(l, (char_u *)"(", NULL))
  941. !             {
  942. !             /* look for opening unmatched paren, indent one level
  943. !              * for each additional level */
  944. !             n = 1;
  945. !             for (col = 0; col < our_paren_pos.col; ++col)
  946. !             {
  947. !                 switch (l[col])
  948. !                 {
  949. !                 case '(':
  950. !                 case '{': ++n;
  951. !                       break;
  952. !                 case ')':
  953. !                 case '}': if (n > 1)
  954. !                           --n;
  955. !                       break;
  956. !                 }
  957. !             }
  958. !             our_paren_pos.col = 0;
  959. !             amount += n * ind_unclosed_wrapped;
  960. !             }
  961. !             else if (ind_unclosed_whiteok)
  962.               our_paren_pos.col++;
  963.               else
  964.               {
  965.               col = our_paren_pos.col + 1;
  966.               while (vim_iswhite(l[col]))
  967.                   col++;
  968.               if (l[col] != NUL)    /* In case of trailing space */
  969. ***************
  970. *** 5522,5529 ****
  971.            * Find how indented the paren is, or the character after it
  972.            * if we did the above "if".
  973.            */
  974. !         getvcol(curwin, &our_paren_pos, &col, NULL, NULL);
  975. !         cur_amount = col;
  976.           }
  977.   
  978.           if (theline[0] == ')' && ind_matching_paren)
  979. --- 5925,5936 ----
  980.            * Find how indented the paren is, or the character after it
  981.            * if we did the above "if".
  982.            */
  983. !         if (our_paren_pos.col > 0)
  984. !         {
  985. !             getvcol(curwin, &our_paren_pos, &col, NULL, NULL);
  986. !             if (cur_amount > (int)col)
  987. !             cur_amount = col;
  988. !         }
  989.           }
  990.   
  991.           if (theline[0] == ')' && ind_matching_paren)
  992. ***************
  993. *** 5532,5538 ****
  994.           }
  995.           else if (ind_unclosed == 0 || (!ind_unclosed_noignore
  996.                             && *skipwhite(look) == '('))
  997. !         amount = cur_amount;
  998.           else
  999.           {
  1000.           /* add ind_unclosed2 for each '(' before our matching one */
  1001. --- 5939,5948 ----
  1002.           }
  1003.           else if (ind_unclosed == 0 || (!ind_unclosed_noignore
  1004.                             && *skipwhite(look) == '('))
  1005. !         {
  1006. !         if (cur_amount != MAXCOL)
  1007. !             amount = cur_amount;
  1008. !         }
  1009.           else
  1010.           {
  1011.           /* add ind_unclosed2 for each '(' before our matching one */
  1012. ***************
  1013. *** 5622,5629 ****
  1014.            * matching it will take us back to the start of the line.
  1015.            */
  1016.           lnum = ourscope;
  1017. !         if (find_last_paren(start) &&
  1018. !             (trypos = find_match_paren(ind_maxparen,
  1019.                                ind_maxcomment)) != NULL)
  1020.           lnum = trypos->lnum;
  1021.   
  1022. --- 6032,6039 ----
  1023.            * matching it will take us back to the start of the line.
  1024.            */
  1025.           lnum = ourscope;
  1026. !         if (find_last_paren(start, '(', ')')
  1027. !             && (trypos = find_match_paren(ind_maxparen,
  1028.                                ind_maxcomment)) != NULL)
  1029.           lnum = trypos->lnum;
  1030.   
  1031. ***************
  1032. *** 5662,5674 ****
  1033.            * If we're looking at a "while", try to find a "do"
  1034.            * to match it with.
  1035.            */
  1036. !         lookfor = 0;
  1037.           if (cin_iselse(theline))
  1038.           lookfor = LOOKFOR_IF;
  1039.           else if (cin_iswhileofdo(theline, cur_curpos.lnum, ind_maxparen))
  1040.                                       /* XXX */
  1041.           lookfor = LOOKFOR_DO;
  1042. !         if (lookfor)
  1043.           {
  1044.           curwin->w_cursor.lnum = cur_curpos.lnum;
  1045.           if (find_match(lookfor, ourscope, ind_maxparen,
  1046. --- 6072,6084 ----
  1047.            * If we're looking at a "while", try to find a "do"
  1048.            * to match it with.
  1049.            */
  1050. !         lookfor = LOOKFOR_INITIAL;
  1051.           if (cin_iselse(theline))
  1052.           lookfor = LOOKFOR_IF;
  1053.           else if (cin_iswhileofdo(theline, cur_curpos.lnum, ind_maxparen))
  1054.                                       /* XXX */
  1055.           lookfor = LOOKFOR_DO;
  1056. !         if (lookfor != LOOKFOR_INITIAL)
  1057.           {
  1058.           curwin->w_cursor.lnum = cur_curpos.lnum;
  1059.           if (find_match(lookfor, ourscope, ind_maxparen,
  1060. ***************
  1061. *** 5709,5714 ****
  1062. --- 6119,6126 ----
  1063.           }
  1064.           }
  1065.   
  1066. +         lookfor_break = FALSE;
  1067.           if (cin_iscase(theline))    /* it's a switch() label */
  1068.           {
  1069.           lookfor = LOOKFOR_CASE;    /* find a previous switch() label */
  1070. ***************
  1071. *** 5721,5727 ****
  1072.           }
  1073.           else
  1074.           {
  1075. !         lookfor = LOOKFOR_ANY;
  1076.           amount += ind_level;    /* ind_level from start of block */
  1077.           }
  1078.           scope_amount = amount;
  1079. --- 6133,6142 ----
  1080.           }
  1081.           else
  1082.           {
  1083. !         if (ind_case_break && cin_isbreak(theline))    /* break; ... */
  1084. !             lookfor_break = TRUE;
  1085. !         lookfor = LOOKFOR_INITIAL;
  1086.           amount += ind_level;    /* ind_level from start of block */
  1087.           }
  1088.           scope_amount = amount;
  1089. ***************
  1090. *** 5747,5755 ****
  1091.            */
  1092.           if (curwin->w_cursor.lnum <= ourscope)
  1093.           {
  1094. !             if (lookfor == LOOKFOR_UNTERM)
  1095. !             amount += ind_continuation;
  1096. !             else if (lookfor != LOOKFOR_TERM)
  1097.               {
  1098.               amount = scope_amount;
  1099.               if (theline[0] == '{')
  1100. --- 6162,6282 ----
  1101.            */
  1102.           if (curwin->w_cursor.lnum <= ourscope)
  1103.           {
  1104. !             /* we reached end of scope:
  1105. !              * if looking for a enum or structure initialization
  1106. !              * go further back:
  1107. !              * if it is an initializer (enum xxx or xxx =), then
  1108. !              * don't add ind_continuation, otherwise it is a variable
  1109. !              * declaration:
  1110. !              * int x,
  1111. !              *     here; <-- add ind_continuation
  1112. !              */
  1113. !             if (lookfor == LOOKFOR_ENUM_OR_INIT)
  1114. !             {
  1115. !             if (curwin->w_cursor.lnum == 0
  1116. !                 || curwin->w_cursor.lnum
  1117. !                             < ourscope - ind_maxparen)
  1118. !             {
  1119. !                 /* nothing found (abuse ind_maxparen as limit)
  1120. !                  * assume terminated line (i.e. a variable
  1121. !                  * initialization) */
  1122. !                 if (cont_amount > 0)
  1123. !                 amount = cont_amount;
  1124. !                 else
  1125. !                 amount += ind_continuation;
  1126. !                 break;
  1127. !             }
  1128. !             l = ml_get_curline();
  1129. !             /*
  1130. !              * If we're in a comment now, skip to the start of the
  1131. !              * comment.
  1132. !              */
  1133. !             trypos = find_start_comment(ind_maxcomment);
  1134. !             if (trypos != NULL)
  1135. !             {
  1136. !                 curwin->w_cursor.lnum = trypos->lnum + 1;
  1137. !                 continue;
  1138. !             }
  1139. !             /*
  1140. !              * Skip preprocessor directives and blank lines.
  1141. !              */
  1142. !             if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
  1143. !                 continue;
  1144. !             if (cin_nocode(l))
  1145. !                 continue;
  1146. !             /*
  1147. !              * If we are at top level and the line looks like a
  1148. !              * function declaration, we are done
  1149. !              * (it's a variable declaration).
  1150. !              */
  1151. !             if (start_brace != BRACE_IN_COL0
  1152. !                 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
  1153. !             {
  1154. !                 terminated = cin_isterminated(l, FALSE, TRUE);
  1155. !                 /* if the line is terminated with another ','
  1156. !                  * it is a continued variable initialization.
  1157. !                  * don't add extra indent.
  1158. !                  * TODO: does not work, if  a function
  1159. !                  * declaration is split over multiple lines:
  1160. !                  * cin_isfuncdecl returns FALSE then.
  1161. !                  */
  1162. !                 if (terminated == ',')
  1163. !                 break;
  1164. !                 /* if it es a enum declaration or an assignment,
  1165. !                  * we are done.
  1166. !                  */
  1167. !                 if (terminated != ';' && cin_isinit())
  1168. !                 break;
  1169. !                 /* nothing useful found */
  1170. !                 if (terminated == 0 || terminated == '{')
  1171. !                 continue;
  1172. !             }
  1173. !             /* Skip parens and braces. Position the cursor over
  1174. !              * the rightmost paren, so that matching it will take
  1175. !              * us back to the start of the line.
  1176. !              */                    /* XXX */
  1177. !             trypos = NULL;
  1178. !             if (find_last_paren(l, '(', ')'))
  1179. !                 trypos = find_match_paren(ind_maxparen,
  1180. !                                   ind_maxcomment);
  1181. !             if (trypos == NULL && find_last_paren(l, '{', '}'))
  1182. !                 trypos = find_start_brace(ind_maxcomment);
  1183. !             if (trypos != NULL)
  1184. !             {
  1185. !                 curwin->w_cursor.lnum = trypos->lnum + 1;
  1186. !                 continue;
  1187. !             }
  1188. !             /* it's a variable declaration, add indentation
  1189. !              * like in
  1190. !              * int a,
  1191. !              *    b;
  1192. !              */
  1193. !             if (cont_amount > 0)
  1194. !                 amount = cont_amount;
  1195. !             else
  1196. !                 amount += ind_continuation;
  1197. !             }
  1198. !             else if (lookfor == LOOKFOR_UNTERM)
  1199. !             {
  1200. !             if (cont_amount > 0)
  1201. !                 amount = cont_amount;
  1202. !             else
  1203. !                 amount += ind_continuation;
  1204. !             }
  1205. !             else if (lookfor != LOOKFOR_TERM
  1206. !                       && lookfor != LOOKFOR_CPP_BASECLASS)
  1207.               {
  1208.               amount = scope_amount;
  1209.               if (theline[0] == '{')
  1210. ***************
  1211. *** 5776,5781 ****
  1212. --- 6303,6313 ----
  1213.           iscase = cin_iscase(l);
  1214.           if (iscase || cin_isscopedecl(l))
  1215.           {
  1216. +             /* we are only looking for cpp base class
  1217. +              * declaration/initialization any longer */
  1218. +             if (lookfor == LOOKFOR_CPP_BASECLASS)
  1219. +             break;
  1220.               /* When looking for a "do" we are not interested in
  1221.                * labels. */
  1222.               if (whilelevel > 0)
  1223. ***************
  1224. *** 5786,5794 ****
  1225.                *        c = 99 +        <- this indent plus continuation
  1226.                *->       here;
  1227.                */
  1228. !             if (lookfor == LOOKFOR_UNTERM)
  1229.               {
  1230. !             amount += ind_continuation;
  1231.               break;
  1232.               }
  1233.   
  1234. --- 6318,6330 ----
  1235.                *        c = 99 +        <- this indent plus continuation
  1236.                *->       here;
  1237.                */
  1238. !             if (lookfor == LOOKFOR_UNTERM
  1239. !                        || lookfor == LOOKFOR_ENUM_OR_INIT)
  1240.               {
  1241. !             if (cont_amount > 0)
  1242. !                 amount = cont_amount;
  1243. !             else
  1244. !                 amount += ind_continuation;
  1245.               break;
  1246.               }
  1247.   
  1248. ***************
  1249. *** 5798,5803 ****
  1250. --- 6334,6340 ----
  1251.                *    case yy:
  1252.                */
  1253.               if (       (iscase && lookfor == LOOKFOR_CASE)
  1254. +                 || (iscase && lookfor_break)
  1255.                   || (!iscase && lookfor == LOOKFOR_SCOPEDECL))
  1256.               {
  1257.               /*
  1258. ***************
  1259. *** 5829,5835 ****
  1260.               {
  1261.               if (n)
  1262.                   amount = n;
  1263. !             break;
  1264.               }
  1265.   
  1266.               /*
  1267. --- 6366,6374 ----
  1268.               {
  1269.               if (n)
  1270.                   amount = n;
  1271. !             if (!lookfor_break)
  1272. !                 break;
  1273.               }
  1274.   
  1275.               /*
  1276. ***************
  1277. *** 5858,5873 ****
  1278.                */
  1279.               scope_amount = get_indent() + (iscase    /* XXX */
  1280.                       ? ind_case_code : ind_scopedecl_code);
  1281. !             lookfor = LOOKFOR_ANY;
  1282.               continue;
  1283.           }
  1284.   
  1285.           /*
  1286.            * Looking for a switch() label or C++ scope declaration,
  1287. !          * ignore other lines.
  1288.            */
  1289.           if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL)
  1290.               continue;
  1291.   
  1292.           /*
  1293.            * Ignore jump labels with nothing after them.
  1294. --- 6397,6417 ----
  1295.                */
  1296.               scope_amount = get_indent() + (iscase    /* XXX */
  1297.                       ? ind_case_code : ind_scopedecl_code);
  1298. !             lookfor = ind_case_break ? LOOKFOR_NOBREAK : LOOKFOR_ANY;
  1299.               continue;
  1300.           }
  1301.   
  1302.           /*
  1303.            * Looking for a switch() label or C++ scope declaration,
  1304. !          * ignore other lines, skip {}-blocks.
  1305.            */
  1306.           if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL)
  1307. +         {
  1308. +             if (find_last_paren(l, '{', '}') && (trypos =
  1309. +                     find_start_brace(ind_maxcomment)) != NULL)
  1310. +             curwin->w_cursor.lnum = trypos->lnum + 1;
  1311.               continue;
  1312. +         }
  1313.   
  1314.           /*
  1315.            * Ignore jump labels with nothing after them.
  1316. ***************
  1317. *** 5886,5898 ****
  1318.            * unlocked it)
  1319.            */
  1320.           l = ml_get_curline();
  1321. !         if (cin_ispreproc(l) || cin_nocode(l))
  1322.               continue;
  1323.   
  1324.           /*
  1325.            * What happens next depends on the line being terminated.
  1326.            */
  1327. !         if (!cin_isterminated(l, FALSE))
  1328.           {
  1329.               /*
  1330.                * if we're in the middle of a paren thing,
  1331. --- 6430,6496 ----
  1332.            * unlocked it)
  1333.            */
  1334.           l = ml_get_curline();
  1335. !         if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)
  1336. !                                  || cin_nocode(l))
  1337.               continue;
  1338.   
  1339.           /*
  1340. +          * Are we at the start of a cpp base class declaration or
  1341. +          * constructor initialization?
  1342. +          */                            /* XXX */
  1343. +         if (lookfor != LOOKFOR_TERM && ind_cpp_baseclass
  1344. +                          && cin_is_cpp_baseclass(l, &col))
  1345. +         {
  1346. +             if (lookfor == LOOKFOR_UNTERM)
  1347. +             {
  1348. +             if (cont_amount > 0)
  1349. +                 amount = cont_amount;
  1350. +             else
  1351. +                 amount += ind_continuation;
  1352. +             }
  1353. +             else if (col == 0 || theline[0] == '{')
  1354. +             {
  1355. +             amount = get_indent();
  1356. +             if (find_last_paren(l, '(', ')')
  1357. +                 && (trypos = find_match_paren(ind_maxparen,
  1358. +                     ind_maxcomment)) != NULL)
  1359. +                 amount = get_indent_lnum(trypos->lnum); /* XXX */
  1360. +             if (theline[0] != '{')
  1361. +                 amount += ind_cpp_baseclass;
  1362. +             }
  1363. +             else
  1364. +             {
  1365. +             curwin->w_cursor.col = col;
  1366. +             getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
  1367. +             amount = (int)col;
  1368. +             }
  1369. +             break;
  1370. +         }
  1371. +         else if (lookfor == LOOKFOR_CPP_BASECLASS)
  1372. +         {
  1373. +             /* only look, whether there is a cpp base class
  1374. +              * declaration or initialization before the opening brace. */
  1375. +             if (cin_isterminated(l, TRUE, FALSE))
  1376. +             break;
  1377. +             else
  1378. +             continue;
  1379. +         }
  1380. +         /*
  1381.            * What happens next depends on the line being terminated.
  1382. +          * If terminated with a ',' only consider it terminating if
  1383. +          * there is anoter unterminated statement behind, eg:
  1384. +          *   123,
  1385. +          *   sizeof
  1386. +          *      here
  1387. +          * Otherwise check whether it is a enumeration or structure
  1388. +          * initialisation (not indented) or a variable declaration
  1389. +          * (indented).
  1390.            */
  1391. !         terminated = cin_isterminated(l, FALSE, TRUE);
  1392. !         if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
  1393. !                             && terminated == ','))
  1394.           {
  1395.               /*
  1396.                * if we're in the middle of a paren thing,
  1397. ***************
  1398. *** 5905,5913 ****
  1399.                * position the cursor over the rightmost paren, so that
  1400.                * matching it will take us back to the start of the line.
  1401.                */
  1402. !             (void)find_last_paren(l);
  1403. !             if ((trypos = find_match_paren(ind_maxparen,
  1404. !                              ind_maxcomment)) != NULL)
  1405.               {
  1406.               /*
  1407.                * Check if we are on a case label now.  This is
  1408. --- 6503,6521 ----
  1409.                * position the cursor over the rightmost paren, so that
  1410.                * matching it will take us back to the start of the line.
  1411.                */
  1412. !             (void)find_last_paren(l, '(', ')');
  1413. !             trypos = find_match_paren(
  1414. !                  corr_ind_maxparen(ind_maxparen, &cur_curpos),
  1415. !                                   ind_maxcomment);
  1416. !             /*
  1417. !              * If we are looking for ',', we also look for matching
  1418. !              * braces.
  1419. !              */
  1420. !             if (trypos == NULL && find_last_paren(l, '{', '}'))
  1421. !             trypos = find_start_brace(ind_maxcomment);
  1422. !             if (trypos != NULL)
  1423.               {
  1424.               /*
  1425.                * Check if we are on a case label now.  This is
  1426. ***************
  1427. *** 5925,5930 ****
  1428. --- 6533,6556 ----
  1429.               }
  1430.   
  1431.               /*
  1432. +              * Skip over continuation lines to find the one to get the
  1433. +              * indent from
  1434. +              * char *usethis = "bla\
  1435. +              *         bla",
  1436. +              *      here;
  1437. +              */
  1438. +             if (terminated == ',')
  1439. +             {
  1440. +             while (curwin->w_cursor.lnum > 1)
  1441. +             {
  1442. +                 l = ml_get(curwin->w_cursor.lnum - 1);
  1443. +                 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
  1444. +                 break;
  1445. +                 --curwin->w_cursor.lnum;
  1446. +             }
  1447. +             }
  1448. +             /*
  1449.                * Get indent and pointer to text for current line,
  1450.                * ignoring any jump label.        XXX
  1451.                */
  1452. ***************
  1453. *** 5938,5944 ****
  1454.                * ->    {
  1455.                *        }
  1456.                */
  1457. !             if (lookfor != LOOKFOR_TERM && theline[0] == '{')
  1458.               {
  1459.               amount = cur_amount;
  1460.               /*
  1461. --- 6564,6571 ----
  1462.                * ->    {
  1463.                *        }
  1464.                */
  1465. !             if (terminated != ',' && lookfor != LOOKFOR_TERM
  1466. !                              && theline[0] == '{')
  1467.               {
  1468.               amount = cur_amount;
  1469.               /*
  1470. ***************
  1471. *** 5950,5955 ****
  1472. --- 6577,6590 ----
  1473.                */
  1474.               if (*skipwhite(l) != '{')
  1475.                   amount += ind_open_extra;
  1476. +             if (ind_cpp_baseclass)
  1477. +             {
  1478. +                 /* have to look back, whether it is a cpp base
  1479. +                  * class declaration or initialization */
  1480. +                 lookfor = LOOKFOR_CPP_BASECLASS;
  1481. +                 continue;
  1482. +             }
  1483.               break;
  1484.               }
  1485.   
  1486. ***************
  1487. *** 5966,5974 ****
  1488.                *        100 +
  1489.                * ->        here;
  1490.                */
  1491. !             if (lookfor == LOOKFOR_UNTERM)
  1492.               {
  1493. !                 amount += ind_continuation;
  1494.                   break;
  1495.               }
  1496.   
  1497. --- 6601,6613 ----
  1498.                *        100 +
  1499.                * ->        here;
  1500.                */
  1501. !             if (lookfor == LOOKFOR_UNTERM
  1502. !                        || lookfor == LOOKFOR_ENUM_OR_INIT)
  1503.               {
  1504. !                 if (cont_amount > 0)
  1505. !                 amount = cont_amount;
  1506. !                 else
  1507. !                 amount += ind_continuation;
  1508.                   break;
  1509.               }
  1510.   
  1511. ***************
  1512. *** 6040,6056 ****
  1513.                * ->        here;
  1514.                */
  1515.               if (lookfor == LOOKFOR_UNTERM)
  1516.                   break;
  1517.   
  1518. !             /*
  1519. !              * Found first unterminated line on a row, may line up
  1520. !              * with this line, remember its indent
  1521. !              *        100 +
  1522. !              * ->        here;
  1523. !              */
  1524. !             amount = cur_amount;
  1525. !             if (lookfor != LOOKFOR_TERM)
  1526. !                 lookfor = LOOKFOR_UNTERM;
  1527.               }
  1528.           }
  1529.   
  1530. --- 6679,6750 ----
  1531.                * ->        here;
  1532.                */
  1533.               if (lookfor == LOOKFOR_UNTERM)
  1534. +             {
  1535. +                 /* When line ends in a comma add extra indent */
  1536. +                 if (terminated == ',')
  1537. +                 amount += ind_continuation;
  1538.                   break;
  1539. +             }
  1540.   
  1541. !             if (lookfor == LOOKFOR_ENUM_OR_INIT)
  1542. !             {
  1543. !                 /* Found two lines ending in ',', lineup with the
  1544. !                  * lowest one, but check for cpp base class
  1545. !                  * declaration/initialization, if it is an
  1546. !                  * opening brace or we are looking just for
  1547. !                  * enumerations/initializations. */
  1548. !                 if (terminated == ',')
  1549. !                 {
  1550. !                 if (ind_cpp_baseclass == 0)
  1551. !                     break;
  1552. !                 lookfor = LOOKFOR_CPP_BASECLASS;
  1553. !                 continue;
  1554. !                 }
  1555. !                 /* Ignore unterminated lines in between, but
  1556. !                  * reduce indent. */
  1557. !                 if (amount > cur_amount)
  1558. !                 amount = cur_amount;
  1559. !             }
  1560. !             else
  1561. !             {
  1562. !                 /*
  1563. !                  * Found first unterminated line on a row, may
  1564. !                  * line up with this line, remember its indent
  1565. !                  *        100 +
  1566. !                  * ->        here;
  1567. !                  */
  1568. !                 amount = cur_amount;
  1569. !                 /*
  1570. !                  * If previous line ends in ',', check whether we
  1571. !                  * are in an initialization or enum
  1572. !                  * struct xxx =
  1573. !                  * {
  1574. !                  *      sizeof a,
  1575. !                  *      124 };
  1576. !                  * or a normal possible continuation line.
  1577. !                  * but only, of no other statement has been found
  1578. !                  * yet.
  1579. !                  */
  1580. !                 if (lookfor == LOOKFOR_INITIAL && terminated == ',')
  1581. !                 {
  1582. !                 lookfor = LOOKFOR_ENUM_OR_INIT;
  1583. !                 cont_amount = cin_first_id_amount();
  1584. !                 }
  1585. !                 else
  1586. !                 {
  1587. !                 if (lookfor == LOOKFOR_INITIAL
  1588. !                     && *l != NUL
  1589. !                     && l[STRLEN(l) - 1] == '\\')
  1590. !                                 /* XXX */
  1591. !                     cont_amount = cin_get_equal_amount(
  1592. !                                curwin->w_cursor.lnum);
  1593. !                 if (lookfor != LOOKFOR_TERM)
  1594. !                     lookfor = LOOKFOR_UNTERM;
  1595. !                 }
  1596. !             }
  1597.               }
  1598.           }
  1599.   
  1600. ***************
  1601. *** 6069,6077 ****
  1602.                *        100 +        <- line up with this one
  1603.                * ->        here;
  1604.                */
  1605. !             if (lookfor == LOOKFOR_UNTERM)
  1606.               {
  1607. !             amount += ind_continuation;
  1608.               break;
  1609.               }
  1610.   
  1611. --- 6763,6775 ----
  1612.                *        100 +        <- line up with this one
  1613.                * ->        here;
  1614.                */
  1615. !             if (lookfor == LOOKFOR_UNTERM
  1616. !                        || lookfor == LOOKFOR_ENUM_OR_INIT)
  1617.               {
  1618. !             if (cont_amount > 0)
  1619. !                 amount = cont_amount;
  1620. !             else
  1621. !                 amount += ind_continuation;
  1622.               break;
  1623.               }
  1624.   
  1625. ***************
  1626. *** 6095,6100 ****
  1627. --- 6793,6809 ----
  1628.           else
  1629.           {
  1630.               /*
  1631. +              * Skip single break line, if before a switch label. It
  1632. +              * may be lined up with the case label.
  1633. +              */
  1634. +             if (lookfor == LOOKFOR_NOBREAK
  1635. +                   && cin_isbreak(skipwhite(ml_get_curline())))
  1636. +             {
  1637. +             lookfor = LOOKFOR_ANY;
  1638. +             continue;
  1639. +             }
  1640. +             /*
  1641.                * Handle "do {" line.
  1642.                */
  1643.               if (whilelevel > 0)
  1644. ***************
  1645. *** 6114,6123 ****
  1646.                *     x = 1;
  1647.                *     y = foo +
  1648.                * ->    here;
  1649.                */
  1650. !             if (lookfor == LOOKFOR_UNTERM)
  1651.               {
  1652. !             amount += ind_continuation;
  1653.               break;
  1654.               }
  1655.   
  1656. --- 6823,6840 ----
  1657.                *     x = 1;
  1658.                *     y = foo +
  1659.                * ->    here;
  1660. +              * or
  1661. +              *     int x = 1;
  1662. +              *     int foo,
  1663. +              * ->    here;
  1664.                */
  1665. !             if (lookfor == LOOKFOR_UNTERM
  1666. !                        || lookfor == LOOKFOR_ENUM_OR_INIT)
  1667.               {
  1668. !             if (cont_amount > 0)
  1669. !                 amount = cont_amount;
  1670. !             else
  1671. !                 amount += ind_continuation;
  1672.               break;
  1673.               }
  1674.   
  1675. ***************
  1676. *** 6132,6138 ****
  1677.                */
  1678.               if (lookfor == LOOKFOR_TERM)
  1679.               {
  1680. !             if (whilelevel == 0)
  1681.                   break;
  1682.               }
  1683.   
  1684. --- 6849,6855 ----
  1685.                */
  1686.               if (lookfor == LOOKFOR_TERM)
  1687.               {
  1688. !             if (!lookfor_break && whilelevel == 0)
  1689.                   break;
  1690.               }
  1691.   
  1692. ***************
  1693. *** 6153,6160 ****
  1694.                */
  1695.   term_again:
  1696.               l = ml_get_curline();
  1697. !             if (find_last_paren(l) &&
  1698. !                 (trypos = find_match_paren(ind_maxparen,
  1699.                                ind_maxcomment)) != NULL)
  1700.               {
  1701.                   /*
  1702. --- 6870,6877 ----
  1703.                */
  1704.   term_again:
  1705.               l = ml_get_curline();
  1706. !             if (find_last_paren(l, '(', ')')
  1707. !                 && (trypos = find_match_paren(ind_maxparen,
  1708.                                ind_maxcomment)) != NULL)
  1709.               {
  1710.                   /*
  1711. ***************
  1712. *** 6254,6261 ****
  1713.        */
  1714.       else if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
  1715.           && !cin_nocode(theline)
  1716. !         && cin_isfuncdecl(ml_get(cur_curpos.lnum + 1))
  1717. !         && !cin_isterminated(theline, FALSE))
  1718.       {
  1719.           amount = ind_func_type;
  1720.       }
  1721. --- 6971,6980 ----
  1722.        */
  1723.       else if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
  1724.           && !cin_nocode(theline)
  1725. !         && !cin_ends_in(theline, (char_u *)":", NULL)
  1726. !         && !cin_ends_in(theline, (char_u *)",", NULL)
  1727. !         && cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
  1728. !         && !cin_isterminated(theline, FALSE, TRUE))
  1729.       {
  1730.           amount = ind_func_type;
  1731.       }
  1732. ***************
  1733. *** 6283,6293 ****
  1734.           }
  1735.   
  1736.           /*
  1737.            * If the line looks like a function declaration, and we're
  1738.            * not in a comment, put it the left margin.
  1739.            */
  1740. !         if (cin_isfuncdecl(theline))
  1741.               break;
  1742.   
  1743.           /*
  1744.            * Finding the closing '}' of a previous function.  Put
  1745. --- 7002,7092 ----
  1746.           }
  1747.   
  1748.           /*
  1749. +          * Are we at the start of a cpp base class declaration or constructor
  1750. +          * initialization?
  1751. +          */                            /* XXX */
  1752. +         if (ind_cpp_baseclass != 0 && theline[0] != '{'
  1753. +                          && cin_is_cpp_baseclass(l, &col))
  1754. +         {
  1755. +             if (col == 0)
  1756. +             {
  1757. +             amount = get_indent() + ind_cpp_baseclass;  /* XXX */
  1758. +             if (find_last_paren(l, '(', ')')
  1759. +                 && (trypos = find_match_paren(ind_maxparen,
  1760. +                     ind_maxcomment)) != NULL)
  1761. +                 amount = get_indent_lnum(trypos->lnum)
  1762. +                        + ind_cpp_baseclass;        /* XXX */
  1763. +             }
  1764. +             else
  1765. +             {
  1766. +             curwin->w_cursor.col = col;
  1767. +             getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
  1768. +             amount = (int)col;
  1769. +             }
  1770. +             break;
  1771. +         }
  1772. +         /*
  1773. +          * Skip preprocessor directives and blank lines.
  1774. +          */
  1775. +         if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
  1776. +             continue;
  1777. +         if (cin_nocode(l))
  1778. +             continue;
  1779. +         /*
  1780. +          * If the previous line ends in ',', use one level of
  1781. +          * indentation:
  1782. +          * int foo,
  1783. +          *     bar;
  1784. +          * do this before checking for '}' in case of eg.
  1785. +          * enum foobar
  1786. +          * {
  1787. +          *   ...
  1788. +          * } foo,
  1789. +          *   bar;
  1790. +          */
  1791. +         n = 0;
  1792. +         if (cin_ends_in(l, (char_u *)",", NULL)
  1793. +                  || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\'))
  1794. +         {
  1795. +             /* take us back to opening paren */
  1796. +             if (find_last_paren(l, '(', ')')
  1797. +                 && (trypos = find_match_paren(ind_maxparen,
  1798. +                              ind_maxcomment)) != NULL)
  1799. +             curwin->w_cursor.lnum = trypos->lnum;
  1800. +             /* For a line ending in ',' that is a continuation line go
  1801. +              * back to the first line with a backslash:
  1802. +              * char *foo = "bla\
  1803. +              *         bla",
  1804. +              *      here;
  1805. +              */
  1806. +             while (n == 0 && curwin->w_cursor.lnum > 1)
  1807. +             {
  1808. +             l = ml_get(curwin->w_cursor.lnum - 1);
  1809. +             if (*l == NUL || l[STRLEN(l) - 1] != '\\')
  1810. +                 break;
  1811. +             --curwin->w_cursor.lnum;
  1812. +             }
  1813. +             amount = get_indent();        /* XXX */
  1814. +             if (amount == 0)
  1815. +             amount = cin_first_id_amount();
  1816. +             if (amount == 0)
  1817. +             amount = ind_continuation;
  1818. +             break;
  1819. +         }
  1820. +         /*
  1821.            * If the line looks like a function declaration, and we're
  1822.            * not in a comment, put it the left margin.
  1823.            */
  1824. !         if (cin_isfuncdecl(NULL, cur_curpos.lnum))  /* XXX */
  1825.               break;
  1826. +         l = ml_get_curline();
  1827.   
  1828.           /*
  1829.            * Finding the closing '}' of a previous function.  Put
  1830. ***************
  1831. *** 6302,6325 ****
  1832.            * char *string_array[] = { "foo",
  1833.            *     / * x * / "b};ar" }; / * foobar * /
  1834.            */
  1835. !         if (cin_ends_in(l, (char_u *)"};"))
  1836.               break;
  1837.   
  1838.           /*
  1839. -          * Skip preprocessor directives and blank lines.
  1840. -          */
  1841. -         if (cin_ispreproc(l))
  1842. -             continue;
  1843. -         if (cin_nocode(l))
  1844. -             continue;
  1845. -         /*
  1846.            * If the PREVIOUS line is a function declaration, the current
  1847.            * line (and the ones that follow) needs to be indented as
  1848.            * parameters.
  1849.            */
  1850. !         if (cin_isfuncdecl(l))
  1851.           {
  1852.               amount = ind_param;
  1853.               break;
  1854. --- 7101,7115 ----
  1855.            * char *string_array[] = { "foo",
  1856.            *     / * x * / "b};ar" }; / * foobar * /
  1857.            */
  1858. !         if (cin_ends_in(l, (char_u *)"};", NULL))
  1859.               break;
  1860.   
  1861.           /*
  1862.            * If the PREVIOUS line is a function declaration, the current
  1863.            * line (and the ones that follow) needs to be indented as
  1864.            * parameters.
  1865.            */
  1866. !         if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
  1867.           {
  1868.               amount = ind_param;
  1869.               break;
  1870. ***************
  1871. *** 6332,6369 ****
  1872.            *     bar;
  1873.            * indent_to_0 here;
  1874.            */
  1875. !         if (cin_ends_in(l, (char_u*)";"))
  1876.           {
  1877.               l = ml_get(curwin->w_cursor.lnum - 1);
  1878. !             if (cin_ends_in(l, (char_u *)",")
  1879.                   || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
  1880.               break;
  1881.               l = ml_get_curline();
  1882.           }
  1883.   
  1884.           /*
  1885. -          * If the previous line ends in ',', use one level of
  1886. -          * indentation:
  1887. -          * int foo,
  1888. -          *     bar;
  1889. -          */
  1890. -         if (cin_ends_in(l, (char_u *)",")
  1891. -             || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
  1892. -         {
  1893. -             amount = get_indent();
  1894. -             if (amount == 0)
  1895. -             amount = ind_param;
  1896. -             break;
  1897. -         }
  1898. -         /*
  1899.            * Doesn't look like anything interesting -- so just
  1900.            * use the indent of this line.
  1901.            *
  1902.            * Position the cursor over the rightmost paren, so that
  1903.            * matching it will take us back to the start of the line.
  1904.            */
  1905. !         find_last_paren(l);
  1906.   
  1907.           if ((trypos = find_match_paren(ind_maxparen,
  1908.                                ind_maxcomment)) != NULL)
  1909. --- 7122,7144 ----
  1910.            *     bar;
  1911.            * indent_to_0 here;
  1912.            */
  1913. !         if (cin_ends_in(l, (char_u*)";", NULL))
  1914.           {
  1915.               l = ml_get(curwin->w_cursor.lnum - 1);
  1916. !             if (cin_ends_in(l, (char_u *)",", NULL)
  1917.                   || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
  1918.               break;
  1919.               l = ml_get_curline();
  1920.           }
  1921.   
  1922.           /*
  1923.            * Doesn't look like anything interesting -- so just
  1924.            * use the indent of this line.
  1925.            *
  1926.            * Position the cursor over the rightmost paren, so that
  1927.            * matching it will take us back to the start of the line.
  1928.            */
  1929. !         find_last_paren(l, '(', ')');
  1930.   
  1931.           if ((trypos = find_match_paren(ind_maxparen,
  1932.                                ind_maxcomment)) != NULL)
  1933. ***************
  1934. *** 6375,6380 ****
  1935. --- 7150,7174 ----
  1936.           /* add extra indent for a comment */
  1937.           if (cin_iscomment(theline))
  1938.           amount += ind_comment;
  1939. +         /* add extra indent if the previous line ended in a backslash:
  1940. +          *          "asdfasdf\
  1941. +          *          here";
  1942. +          *        char *foo = "asdf\
  1943. +          *             here";
  1944. +          */
  1945. +         if (cur_curpos.lnum > 1)
  1946. +         {
  1947. +         l = ml_get(cur_curpos.lnum - 1);
  1948. +         if (*l != NUL && l[STRLEN(l) - 1] == '\\')
  1949. +         {
  1950. +             cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1);
  1951. +             if (cur_amount > 0)
  1952. +             amount = cur_amount;
  1953. +             else if (cur_amount == 0)
  1954. +             amount += ind_continuation;
  1955. +         }
  1956. +         }
  1957.       }
  1958.       }
  1959.   
  1960. *** ../vim-6.2.503/src/testdir/test3.in    Sun May  4 13:29:30 2003
  1961. --- src/testdir/test3.in    Mon Apr 26 16:56:42 2004
  1962. ***************
  1963. *** 504,509 ****
  1964. --- 504,513 ----
  1965.       int indented;
  1966.   {}
  1967.   
  1968. + char *a[] = {"aaa", "bbb",
  1969. +     "ccc", NULL};
  1970. + // here
  1971.   char *tab[] = {"aaa",
  1972.       "xx", /* xx */};    /* asdf */
  1973.   int not_indented;
  1974. ***************
  1975. *** 523,538 ****
  1976. --- 527,709 ----
  1977.       bar;
  1978.   int foo;
  1979.   
  1980. + #if defined(foo) \
  1981. +     && defined(bar)
  1982.   char * xx = "asdf\
  1983.       foo\
  1984.       bor";
  1985.   int x;
  1986.   
  1987. + char    *foo = "asdf\
  1988. +     asdf\
  1989. +     asdf",
  1990. +     *bar;
  1991. + void f()
  1992. + {
  1993. + #if defined(foo) \
  1994. +     && defined(bar)
  1995. + char    *foo = "asdf\
  1996. +     asdf\
  1997. +     asdf",
  1998. +     *bar;
  1999. +     {
  2000. +     int i;
  2001. + char    *foo = "asdf\
  2002. +     asdf\
  2003. +     asdf",
  2004. +     *bar;
  2005. +     }
  2006. + #endif
  2007. + }
  2008. + #endif
  2009.   int y;        // comment
  2010.           // comment
  2011.   
  2012.       // comment
  2013.   
  2014. + {
  2015. +     Constructor(int a,
  2016. +             int b )  : BaseClass(a)
  2017. +     {
  2018. +     }
  2019. + }
  2020. + void foo()
  2021. + {
  2022. +     char one,
  2023. +     two;
  2024. +     struct bla piet,
  2025. +     jan;
  2026. +     enum foo kees,
  2027. +     jannie;
  2028. +     static unsigned sdf,
  2029. +     krap;
  2030. +     unsigned int piet,
  2031. +     jan;
  2032. +     int
  2033. +     kees,
  2034. +     jan;
  2035. + }
  2036. + {
  2037. +     t(int f,
  2038. +             int d);        // )
  2039. +     d();
  2040. + }
  2041. + Constructor::Constructor(int a,
  2042. +                          int b 
  2043. +                         )  : 
  2044. +    BaseClass(a,
  2045. +              b,
  2046. +              c),
  2047. +    mMember(b),
  2048. + {
  2049. + }
  2050. + Constructor::Constructor(int a,
  2051. +                          int b )  : 
  2052. +    BaseClass(a)
  2053. + {
  2054. + }
  2055. + Constructor::Constructor(int a,
  2056. +                          int b ) /*x*/ : /*x*/ BaseClass(a),
  2057. +                                                member(b)
  2058. + {
  2059. + }
  2060. + class CAbc :
  2061. +    public BaseClass1,
  2062. +    protected BaseClass2
  2063. + {
  2064. +    int Test() { return FALSE; }
  2065. +    int Test1() { return TRUE; }
  2066. +    CAbc(int a, int b )  : 
  2067. +       BaseClass(a)
  2068. +    { 
  2069. +       switch(xxx)
  2070. +       {
  2071. +          case abc:
  2072. +             asdf();
  2073. +             break;
  2074. +          case 999:
  2075. +             baer();
  2076. +             break;
  2077. +       }
  2078. +    }
  2079. + public: // <-- this was incoreectly indented before!!
  2080. +    void testfall();
  2081. + protected:
  2082. +    void testfall();
  2083. + };
  2084. + class CAbc : public BaseClass1,
  2085. +              protected BaseClass2
  2086. + {
  2087. + };
  2088. + static struct
  2089. + {
  2090. +     int a;
  2091. +     int b;
  2092. + } variable[COUNT] =
  2093. + {
  2094. +     {
  2095. +         123,
  2096. +         456
  2097. +     },
  2098. +     {
  2099. +         123,
  2100. +         456
  2101. +     }
  2102. + };
  2103. + static struct
  2104. + {
  2105. +     int a;
  2106. +     int b;
  2107. + } variable[COUNT] =
  2108. + {
  2109. +     { 123, 456 },
  2110. +     { 123, 456 }
  2111. + };
  2112. + void asdf()        /* ind_maxparen may cause trouble here */
  2113. + {
  2114. +     if ((0
  2115. +                 && 1
  2116. +                 && 1
  2117. +                 && 1
  2118. +                 && 1
  2119. +                 && 1
  2120. +                 && 1
  2121. +                 && 1
  2122. +                 && 1
  2123. +                 && 1
  2124. +                 && 1
  2125. +                 && 1
  2126. +                 && 1
  2127. +                 && 1
  2128. +                 && 1
  2129. +                 && 1
  2130. +                 && 1
  2131. +                 && 1
  2132. +                 && 1
  2133. +                 && 1
  2134. +                 && 1
  2135. +                 && 1
  2136. +                 && 1
  2137. +                 && 1
  2138. +                 && 1
  2139. +                 && 1)) break;
  2140. + }
  2141.   /* end of AUTO */
  2142.   
  2143.   STARTTEST
  2144. ***************
  2145. *** 900,905 ****
  2146. --- 1071,1195 ----
  2147.       c1 && c2
  2148.       )
  2149.       foo;
  2150. + }
  2151. + STARTTEST
  2152. + :set cino=b1
  2153. + 2kdd]]=][
  2154. + ENDTEST
  2155. + void f()
  2156. + {
  2157. +     switch (x)
  2158. +     {
  2159. +         case 1:
  2160. +             a = b;
  2161. +             break;
  2162. +         default:
  2163. +             a = 0;
  2164. +             break;
  2165. +     }
  2166. + }
  2167. + STARTTEST
  2168. + :set cino=(0,W5
  2169. + 2kdd]]=][
  2170. + ENDTEST
  2171. + void f()
  2172. + {
  2173. +     invokeme(
  2174. +     argu,
  2175. +     ment);
  2176. +     invokeme(
  2177. +     argu,
  2178. +     ment
  2179. +     );
  2180. +     invokeme(argu,
  2181. +     ment
  2182. +     );
  2183. + }
  2184. + STARTTEST
  2185. + :set cino=/6
  2186. + 2kdd]]=][
  2187. + ENDTEST
  2188. + void f()
  2189. + {
  2190. +     statement;
  2191. +         // comment 1
  2192. +     // comment 2
  2193. + }
  2194. + STARTTEST
  2195. + :set cino=
  2196. + 2kdd]]/comment 1/+1
  2197. + ==
  2198. + ENDTEST
  2199. + void f()
  2200. + {
  2201. +     statement;
  2202. +        // comment 1
  2203. +     // comment 2
  2204. + }
  2205. + STARTTEST
  2206. + :set cino=g0
  2207. + 2kdd]]=][
  2208. + ENDTEST
  2209. + class CAbc
  2210. + {
  2211. +    int Test() { return FALSE; }
  2212. + public: // comment
  2213. +    void testfall();
  2214. + protected:
  2215. +    void testfall();
  2216. + };
  2217. + STARTTEST
  2218. + :set cino=(0,W2s
  2219. + 2kdd]]=][
  2220. + ENDTEST
  2221. + {
  2222. +    averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
  2223. +          asdasdf,
  2224. +          func(asdf,
  2225. +               asdfadsf),
  2226. +          asdfasdf
  2227. +          );
  2228. +    /* those are ugly, but consequent */
  2229. +    func()->asd(asdasdf,
  2230. +                averylongfunctionname(
  2231. +                      abc,
  2232. +                      dec)->averylongfunctionname(
  2233. +                            asdfadsf,
  2234. +                            asdfasdf,
  2235. +                            asdfasdf,
  2236. +                            ),
  2237. +                func(asdfadf,
  2238. +                     asdfasdf
  2239. +                    ),
  2240. +                asdasdf
  2241. +               );
  2242. +    averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
  2243. +                abc,
  2244. +                dec)->asdfasdfasdf(
  2245. +                      asdfadsf,
  2246. +                      asdfasdf,
  2247. +                      asdfasdf,
  2248. +                      ),
  2249. +          func(asdfadf,
  2250. +               asdfasdf),
  2251. +          asdasdf
  2252. +          );
  2253.   }
  2254.   
  2255.   STARTTEST
  2256. *** ../vim-6.2.503/src/testdir/test3.ok    Sun May  4 13:29:34 2003
  2257. --- src/testdir/test3.ok    Mon Apr 26 16:57:16 2004
  2258. ***************
  2259. *** 492,497 ****
  2260. --- 492,501 ----
  2261.       int indented;
  2262.   {}
  2263.   
  2264. + char *a[] = {"aaa", "bbb",
  2265. +     "ccc", NULL};
  2266. + // here
  2267.   char *tab[] = {"aaa",
  2268.       "xx", /* xx */};    /* asdf */
  2269.   int not_indented;
  2270. ***************
  2271. *** 511,526 ****
  2272.       bar;
  2273.   int foo;
  2274.   
  2275.   char * xx = "asdf\
  2276. !     foo\
  2277. !     bor";
  2278.   int x;
  2279.   
  2280.   int y;        // comment
  2281.   // comment
  2282.   
  2283.   // comment
  2284.   
  2285.   /* end of AUTO */
  2286.   
  2287.   
  2288. --- 515,697 ----
  2289.       bar;
  2290.   int foo;
  2291.   
  2292. + #if defined(foo) \
  2293. +     && defined(bar)
  2294.   char * xx = "asdf\
  2295. !              foo\
  2296. !              bor";
  2297.   int x;
  2298.   
  2299. + char    *foo = "asdf\
  2300. +                 asdf\
  2301. +                 asdf",
  2302. +         *bar;
  2303. + void f()
  2304. + {
  2305. + #if defined(foo) \
  2306. +     && defined(bar)
  2307. +     char    *foo = "asdf\
  2308. +                     asdf\
  2309. +                     asdf",
  2310. +             *bar;
  2311. +     {
  2312. +         int i;
  2313. +         char    *foo = "asdf\
  2314. +                         asdf\
  2315. +                         asdf",
  2316. +                 *bar;
  2317. +     }
  2318. + #endif
  2319. + }
  2320. + #endif
  2321.   int y;        // comment
  2322.   // comment
  2323.   
  2324.   // comment
  2325.   
  2326. + {
  2327. +     Constructor(int a,
  2328. +             int b )  : BaseClass(a)
  2329. +     {
  2330. +     }
  2331. + }
  2332. + void foo()
  2333. + {
  2334. +     char one,
  2335. +          two;
  2336. +     struct bla piet,
  2337. +                jan;
  2338. +     enum foo kees,
  2339. +              jannie;
  2340. +     static unsigned sdf,
  2341. +                     krap;
  2342. +     unsigned int piet,
  2343. +                  jan;
  2344. +     int
  2345. +         kees,
  2346. +         jan;
  2347. + }
  2348. + {
  2349. +     t(int f,
  2350. +             int d);        // )
  2351. +     d();
  2352. + }
  2353. + Constructor::Constructor(int a,
  2354. +         int b 
  2355. +         )  : 
  2356. +     BaseClass(a,
  2357. +             b,
  2358. +             c),
  2359. +     mMember(b),
  2360. + {
  2361. + }
  2362. + Constructor::Constructor(int a,
  2363. +         int b )  : 
  2364. +     BaseClass(a)
  2365. + {
  2366. + }
  2367. + Constructor::Constructor(int a,
  2368. +         int b ) /*x*/ : /*x*/ BaseClass(a),
  2369. +                               member(b)
  2370. + {
  2371. + }
  2372. + class CAbc :
  2373. +     public BaseClass1,
  2374. +     protected BaseClass2
  2375. + {
  2376. +     int Test() { return FALSE; }
  2377. +     int Test1() { return TRUE; }
  2378. +     CAbc(int a, int b )  : 
  2379. +         BaseClass(a)
  2380. +     { 
  2381. +         switch(xxx)
  2382. +         {
  2383. +             case abc:
  2384. +                 asdf();
  2385. +                 break;
  2386. +             case 999:
  2387. +                 baer();
  2388. +                 break;
  2389. +         }
  2390. +     }
  2391. +     public: // <-- this was incoreectly indented before!!
  2392. +     void testfall();
  2393. +     protected:
  2394. +     void testfall();
  2395. + };
  2396. + class CAbc : public BaseClass1,
  2397. +              protected BaseClass2
  2398. + {
  2399. + };
  2400. + static struct
  2401. + {
  2402. +     int a;
  2403. +     int b;
  2404. + } variable[COUNT] =
  2405. + {
  2406. +     {
  2407. +         123,
  2408. +         456
  2409. +     },
  2410. +     {
  2411. +         123,
  2412. +         456
  2413. +     }
  2414. + };
  2415. + static struct
  2416. + {
  2417. +     int a;
  2418. +     int b;
  2419. + } variable[COUNT] =
  2420. + {
  2421. +     { 123, 456 },
  2422. +     { 123, 456 }
  2423. + };
  2424. + void asdf()        /* ind_maxparen may cause trouble here */
  2425. + {
  2426. +     if ((0
  2427. +                 && 1
  2428. +                 && 1
  2429. +                 && 1
  2430. +                 && 1
  2431. +                 && 1
  2432. +                 && 1
  2433. +                 && 1
  2434. +                 && 1
  2435. +                 && 1
  2436. +                 && 1
  2437. +                 && 1
  2438. +                 && 1
  2439. +                 && 1
  2440. +                 && 1
  2441. +                 && 1
  2442. +                 && 1
  2443. +                 && 1
  2444. +                 && 1
  2445. +                 && 1
  2446. +                 && 1
  2447. +                 && 1
  2448. +                 && 1
  2449. +                 && 1
  2450. +                 && 1
  2451. +                 && 1)) break;
  2452. + }
  2453.   /* end of AUTO */
  2454.   
  2455.   
  2456. ***************
  2457. *** 802,806 ****
  2458. --- 973,1071 ----
  2459.           c1 && c2
  2460.       )
  2461.           foo;
  2462. + }
  2463. + void f()
  2464. + {
  2465. +     switch (x)
  2466. +     {
  2467. +         case 1:
  2468. +             a = b;
  2469. +         break;
  2470. +         default:
  2471. +             a = 0;
  2472. +         break;
  2473. +     }
  2474. + }
  2475. + void f()
  2476. + {
  2477. +     invokeme(
  2478. +          argu,
  2479. +          ment);
  2480. +     invokeme(
  2481. +          argu,
  2482. +          ment
  2483. +          );
  2484. +     invokeme(argu,
  2485. +              ment
  2486. +             );
  2487. + }
  2488. + void f()
  2489. + {
  2490. +     statement;
  2491. +           // comment 1
  2492. +           // comment 2
  2493. + }
  2494. + void f()
  2495. + {
  2496. +     statement;
  2497. +        // comment 1
  2498. +        // comment 2
  2499. + }
  2500. + class CAbc
  2501. + {
  2502. +     int Test() { return FALSE; }
  2503. + public: // comment
  2504. +     void testfall();
  2505. + protected:
  2506. +     void testfall();
  2507. + };
  2508. + {
  2509. +     averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
  2510. +             asdasdf,
  2511. +             func(asdf,
  2512. +                  asdfadsf),
  2513. +             asdfasdf
  2514. +             );
  2515. +     /* those are ugly, but consequent */
  2516. +     func()->asd(asdasdf,
  2517. +                 averylongfunctionname(
  2518. +                         abc,
  2519. +                         dec)->averylongfunctionname(
  2520. +                                 asdfadsf,
  2521. +                                 asdfasdf,
  2522. +                                 asdfasdf,
  2523. +                                 ),
  2524. +                 func(asdfadf,
  2525. +                      asdfasdf
  2526. +                     ),
  2527. +                 asdasdf
  2528. +                );
  2529. +     averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
  2530. +                     abc,
  2531. +                     dec)->asdfasdfasdf(
  2532. +                             asdfadsf,
  2533. +                             asdfasdf,
  2534. +                             asdfasdf,
  2535. +                             ),
  2536. +             func(asdfadf,
  2537. +                  asdfasdf),
  2538. +             asdasdf
  2539. +             );
  2540.   }
  2541.   
  2542. *** ../vim-6.2.503/src/version.c    Mon Apr 26 12:37:27 2004
  2543. --- src/version.c    Mon Apr 26 18:54:36 2004
  2544. ***************
  2545. *** 639,640 ****
  2546. --- 639,642 ----
  2547.   {   /* Add new patch number below this line */
  2548. + /**/
  2549. +     504,
  2550.   /**/
  2551.  
  2552. -- 
  2553. `The Guide says there is an art to flying,' said Ford, `or at least a
  2554. knack. The knack lies in learning how to throw yourself at the ground
  2555. and miss.' He smiled weakly.
  2556.         -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
  2557.  
  2558.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  2559. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  2560. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  2561.  \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
  2562.