Skip to content

Commit 67f8ab8

Browse files
committed
patch 8.1.0369: continuation lines cannot contain comments
Problem: Continuation lines cannot contain comments. Solution: Support using "\ .
1 parent 25328e3 commit 67f8ab8

File tree

5 files changed

+63
-23
lines changed

5 files changed

+63
-23
lines changed

runtime/doc/repeat.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@ flag when defining the function, it is not relevant when executing it. >
465465
.
466466
:endfunction
467467
:set cpo-=C
468+
<
469+
*line-continuation-comment*
470+
To add a comment in between the lines start with '\" '. Notice the space
471+
after the double quote. Example: >
472+
let array = [
473+
"\ first entry comment
474+
\ 'first',
475+
"\ second entry comment
476+
\ 'second',
477+
\ ]
468478
469479
Rationale:
470480
Most programs work with a trailing backslash to indicate line
@@ -473,6 +483,14 @@ Rationale:
473483
:map xx asdf\
474484
< Therefore the unusual leading backslash is used.
475485

486+
Starting a comment in a continuation line results in all following
487+
continuation lines to be part of the comment. Since it was like this
488+
for a long time, when making it possible to add a comment halfway a
489+
sequence of continuation lines, it was not possible to use \", since
490+
that was a valid continuation line. Using '"\ ' comes closest, even
491+
though it may look a bit weird. Requiring the space after the
492+
backslash is to make it very unlikely this is a normal comment line.
493+
476494
==============================================================================
477495
5. Using Vim packages *packages*
478496

runtime/indent/vim.vim

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif
1010
let b:did_indent = 1
1111

1212
setlocal indentexpr=GetVimIndent()
13-
setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\
13+
setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\,0=\"\\\
1414

1515
let b:undo_indent = "setl indentkeys< indentexpr<"
1616

@@ -31,15 +31,17 @@ function GetVimIndent()
3131
endtry
3232
endfunc
3333

34+
let s:lineContPat = '^\s*\(\\\|"\\ \)'
35+
3436
function GetVimIndentIntern()
3537
" Find a non-blank line above the current line.
3638
let lnum = prevnonblank(v:lnum - 1)
3739

38-
" If the current line doesn't start with '\' and below a line that starts
39-
" with '\', use the indent of the line above it.
40+
" If the current line doesn't start with '\' or '"\ ' and below a line that
41+
" starts with '\' or '"\ ', use the indent of the line above it.
4042
let cur_text = getline(v:lnum)
41-
if cur_text !~ '^\s*\\'
42-
while lnum > 0 && getline(lnum) =~ '^\s*\\'
43+
if cur_text !~ s:lineContPat
44+
while lnum > 0 && getline(lnum) =~ s:lineContPat
4345
let lnum = lnum - 1
4446
endwhile
4547
endif
@@ -51,10 +53,10 @@ function GetVimIndentIntern()
5153
let prev_text = getline(lnum)
5254

5355
" Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
54-
" and :else. Add it three times for a line that starts with '\' after
55-
" a line that doesn't (or g:vim_indent_cont if it exists).
56+
" and :else. Add it three times for a line that starts with '\' or '"\ '
57+
" after a line that doesn't (or g:vim_indent_cont if it exists).
5658
let ind = indent(lnum)
57-
if cur_text =~ '^\s*\\' && v:lnum > 1 && prev_text !~ '^\s*\\'
59+
if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat
5860
if exists("g:vim_indent_cont")
5961
let ind = ind + g:vim_indent_cont
6062
else

src/ex_cmds2.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4864,36 +4864,43 @@ getsourceline(int c UNUSED, void *cookie, int indent UNUSED)
48644864
/* compensate for the one line read-ahead */
48654865
--sourcing_lnum;
48664866

4867-
/* Get the next line and concatenate it when it starts with a
4868-
* backslash. We always need to read the next line, keep it in
4869-
* sp->nextline. */
4867+
// Get the next line and concatenate it when it starts with a
4868+
// backslash. We always need to read the next line, keep it in
4869+
// sp->nextline.
4870+
/* Also check for a comment in between continuation lines: "\ */
48704871
sp->nextline = get_one_sourceline(sp);
4871-
if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\')
4872+
if (sp->nextline != NULL
4873+
&& (*(p = skipwhite(sp->nextline)) == '\\'
4874+
|| (p[0] == '"' && p[1] == '\\' && p[2] == ' ')))
48724875
{
48734876
garray_T ga;
48744877

48754878
ga_init2(&ga, (int)sizeof(char_u), 400);
48764879
ga_concat(&ga, line);
4877-
ga_concat(&ga, p + 1);
4880+
if (*p == '\\')
4881+
ga_concat(&ga, p + 1);
48784882
for (;;)
48794883
{
48804884
vim_free(sp->nextline);
48814885
sp->nextline = get_one_sourceline(sp);
48824886
if (sp->nextline == NULL)
48834887
break;
48844888
p = skipwhite(sp->nextline);
4885-
if (*p != '\\')
4886-
break;
4887-
/* Adjust the growsize to the current length to speed up
4888-
* concatenating many lines. */
4889-
if (ga.ga_len > 400)
4889+
if (*p == '\\')
48904890
{
4891-
if (ga.ga_len > 8000)
4892-
ga.ga_growsize = 8000;
4893-
else
4894-
ga.ga_growsize = ga.ga_len;
4891+
// Adjust the growsize to the current length to speed up
4892+
// concatenating many lines.
4893+
if (ga.ga_len > 400)
4894+
{
4895+
if (ga.ga_len > 8000)
4896+
ga.ga_growsize = 8000;
4897+
else
4898+
ga.ga_growsize = ga.ga_len;
4899+
}
4900+
ga_concat(&ga, p + 1);
48954901
}
4896-
ga_concat(&ga, p + 1);
4902+
else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ')
4903+
break;
48974904
}
48984905
ga_append(&ga, NUL);
48994906
vim_free(line);

src/testdir/test_eval_stuff.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,14 @@ func Test_mkdir_p()
4242
call delete('Xfile')
4343
call delete('Xmkdir', 'rf')
4444
endfunc
45+
46+
func Test_line_continuation()
47+
let array = [5,
48+
"\ ignore this
49+
\ 6,
50+
"\ more to ignore
51+
"\ more moreto ignore
52+
\ ]
53+
"\ and some more
54+
call assert_equal([5, 6], array)
55+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
369,
797799
/**/
798800
368,
799801
/**/

0 commit comments

Comments
 (0)