To: vim_dev@googlegroups.com Subject: Patch 8.0.0148 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0148 Problem: When a C preprocessor statement has two line continuations the following line does not have the right indent. (Ken Takata) Solution: Add the indent of the previous continuation line. (Hirohito Higashi) Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok *** ../vim-8.0.0147/src/misc1.c 2016-11-17 21:30:17.144445729 +0100 --- src/misc1.c 2017-01-07 14:09:00.601851661 +0100 *************** *** 5422,5428 **** static int cin_first_id_amount(void); static int cin_get_equal_amount(linenr_T lnum); static int cin_ispreproc(char_u *); - static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump); static int cin_iscomment(char_u *); static int cin_islinecomment(char_u *); static int cin_isterminated(char_u *, int, int); --- 5422,5427 ---- *************** *** 6002,6014 **** * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a * continuation line of a preprocessor statement. Decrease "*lnump" to the * start and return the line in "*pp". */ static int ! cin_ispreproc_cont(char_u **pp, linenr_T *lnump) { char_u *line = *pp; linenr_T lnum = *lnump; int retval = FALSE; for (;;) { --- 6001,6018 ---- * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a * continuation line of a preprocessor statement. Decrease "*lnump" to the * start and return the line in "*pp". + * Put the amount of indent in "*amount". */ static int ! cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount) { char_u *line = *pp; linenr_T lnum = *lnump; int retval = FALSE; + int candidate_amount = *amount; + + if (*line != NUL && line[STRLEN(line) - 1] == '\\') + candidate_amount = get_indent_lnum(lnum); for (;;) { *************** *** 6027,6032 **** --- 6031,6038 ---- if (lnum != *lnump) *pp = ml_get(*lnump); + if (retval) + *amount = candidate_amount; return retval; } *************** *** 7390,7396 **** l = skipwhite(ml_get(lnum)); if (cin_nocode(l)) /* skip comment lines */ continue; ! if (cin_ispreproc_cont(&l, &lnum)) continue; /* ignore #define, #if, etc. */ curwin->w_cursor.lnum = lnum; --- 7396,7402 ---- l = skipwhite(ml_get(lnum)); if (cin_nocode(l)) /* skip comment lines */ continue; ! if (cin_ispreproc_cont(&l, &lnum, &amount)) continue; /* ignore #define, #if, etc. */ curwin->w_cursor.lnum = lnum; *************** *** 7803,7812 **** */ if (curwin->w_cursor.lnum <= ourscope) { ! /* we reached end of scope: ! * if looking for a enum or structure initialization * go further back: ! * if it is an initializer (enum xxx or xxx =), then * don't add ind_continuation, otherwise it is a variable * declaration: * int x, --- 7809,7818 ---- */ if (curwin->w_cursor.lnum <= ourscope) { ! /* We reached end of scope: ! * If looking for a enum or structure initialization * go further back: ! * If it is an initializer (enum xxx or xxx =), then * don't add ind_continuation, otherwise it is a variable * declaration: * int x, *************** *** 7845,7851 **** /* * Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) continue; if (cin_nocode(l)) --- 7851,7858 ---- /* * Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, ! &amount)) continue; if (cin_nocode(l)) *************** *** 7962,7968 **** } /* Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) continue; /* Finally the actual check for "namespace". */ --- 7969,7976 ---- } /* Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, ! &amount)) continue; /* Finally the actual check for "namespace". */ *************** *** 8138,8144 **** * unlocked it) */ l = ml_get_curline(); ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum) || cin_nocode(l)) continue; --- 8146,8152 ---- * unlocked it) */ l = ml_get_curline(); ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount) || cin_nocode(l)) continue; *************** *** 8859,8865 **** /* * Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) continue; if (cin_nocode(l)) --- 8867,8873 ---- /* * Skip preprocessor directives and blank lines. */ ! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) continue; if (cin_nocode(l)) *************** *** 8960,8966 **** { look = ml_get(--curwin->w_cursor.lnum); if (!(cin_nocode(look) || cin_ispreproc_cont( ! &look, &curwin->w_cursor.lnum))) break; } if (curwin->w_cursor.lnum > 0 --- 8968,8974 ---- { look = ml_get(--curwin->w_cursor.lnum); if (!(cin_nocode(look) || cin_ispreproc_cont( ! &look, &curwin->w_cursor.lnum, &amount))) break; } if (curwin->w_cursor.lnum > 0 *** ../vim-8.0.0147/src/testdir/test3.in 2016-11-17 21:30:17.144445729 +0100 --- src/testdir/test3.in 2017-01-07 14:03:05.980471398 +0100 *************** *** 2318,2323 **** --- 2318,2342 ---- JSEND STARTTEST + :set cin cino& + /start of define + =/end of define + ENDTEST + + /* start of define */ + { + } + #define AAA \ + BBB\ + CCC + + #define CNT \ + 1 + \ + 2 + \ + 4 + /* end of define */ + + STARTTEST :g/^STARTTEST/.,/^ENDTEST/d :1;/start of AUTO/,$wq! test.out ENDTEST *** ../vim-8.0.0147/src/testdir/test3.ok 2016-11-17 21:30:17.144445729 +0100 --- src/testdir/test3.ok 2017-01-07 14:03:05.980471398 +0100 *************** *** 2080,2082 **** --- 2080,2096 ---- i; JSEND + + /* start of define */ + { + } + #define AAA \ + BBB\ + CCC + + #define CNT \ + 1 + \ + 2 + \ + 4 + /* end of define */ + *** ../vim-8.0.0147/src/version.c 2017-01-06 20:03:45.430748917 +0100 --- src/version.c 2017-01-07 14:02:42.520644763 +0100 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 148, /**/ -- Spam seems to be something useful to novices. Later you realize that it's a bunch of indigestable junk that only clogs your system. Applies to both the food and the e-mail! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///