diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-05-03 01:45:35 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-05-03 02:08:18 -0400 |
commit | 96a8b0ab787c7d7148eb4c9881fdb5e022996081 (patch) | |
tree | 27565ee941cd97515399964f5e22018817a9d022 | |
parent | 4b287119fe798da1ca1ae5b96f6503972ed3a229 (diff) | |
download | rneovim-96a8b0ab787c7d7148eb4c9881fdb5e022996081.tar.gz rneovim-96a8b0ab787c7d7148eb4c9881fdb5e022996081.tar.bz2 rneovim-96a8b0ab787c7d7148eb4c9881fdb5e022996081.zip |
vim-patch:8.1.0369: continuation lines cannot contain comments
Problem: Continuation lines cannot contain comments.
Solution: Support using "\ .
https://github.com/vim/vim/commit/67f8ab829911c7901c534ef2bf19cc34b622936f
-rw-r--r-- | runtime/doc/repeat.txt | 18 | ||||
-rw-r--r-- | runtime/indent/vim.vim | 18 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 24 | ||||
-rw-r--r-- | src/nvim/testdir/test_eval_stuff.vim | 11 |
4 files changed, 54 insertions, 17 deletions
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index 23ae3458ea..0a552a1309 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -432,6 +432,16 @@ flag when defining the function, it is not relevant when executing it. > . :endfunction :set cpo-=C +< + *line-continuation-comment* +To add a comment in between the lines start with '\" '. Notice the space +after the double quote. Example: > + let array = [ + "\ first entry comment + \ 'first', + "\ second entry comment + \ 'second', + \ ] Rationale: Most programs work with a trailing backslash to indicate line @@ -440,6 +450,14 @@ Rationale: :map xx asdf\ < Therefore the unusual leading backslash is used. + Starting a comment in a continuation line results in all following + continuation lines to be part of the comment. Since it was like this + for a long time, when making it possible to add a comment halfway a + sequence of continuation lines, it was not possible to use \", since + that was a valid continuation line. Using '"\ ' comes closest, even + though it may look a bit weird. Requiring the space after the + backslash is to make it very unlikely this is a normal comment line. + ============================================================================== 5. Using Vim packages *packages* diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim index 8ebfa12caf..cd735c3a3c 100644 --- a/runtime/indent/vim.vim +++ b/runtime/indent/vim.vim @@ -10,7 +10,7 @@ endif let b:did_indent = 1 setlocal indentexpr=GetVimIndent() -setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\ +setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\,0=\"\\\ let b:undo_indent = "setl indentkeys< indentexpr<" @@ -31,15 +31,17 @@ function GetVimIndent() endtry endfunc +let s:lineContPat = '^\s*\(\\\|"\\ \)' + function GetVimIndentIntern() " Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1) - " If the current line doesn't start with '\' and below a line that starts - " with '\', use the indent of the line above it. + " If the current line doesn't start with '\' or '"\ ' and below a line that + " starts with '\' or '"\ ', use the indent of the line above it. let cur_text = getline(v:lnum) - if cur_text !~ '^\s*\\' - while lnum > 0 && getline(lnum) =~ '^\s*\\' + if cur_text !~ s:lineContPat + while lnum > 0 && getline(lnum) =~ s:lineContPat let lnum = lnum - 1 endwhile endif @@ -51,10 +53,10 @@ function GetVimIndentIntern() let prev_text = getline(lnum) " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function - " and :else. Add it three times for a line that starts with '\' after - " a line that doesn't (or g:vim_indent_cont if it exists). + " and :else. Add it three times for a line that starts with '\' or '"\ ' + " after a line that doesn't (or g:vim_indent_cont if it exists). let ind = indent(lnum) - if cur_text =~ '^\s*\\' && v:lnum > 1 && prev_text !~ '^\s*\\' + if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat if exists("g:vim_indent_cont") let ind = ind + g:vim_indent_cont else diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 15b735dc9e..53a5018fe0 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3403,13 +3403,18 @@ char_u *getsourceline(int c, void *cookie, int indent) // Get the next line and concatenate it when it starts with a // backslash. We always need to read the next line, keep it in // sp->nextline. + // Also check for a comment in between continuation lines: "\ . sp->nextline = get_one_sourceline(sp); - if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\') { + if (sp->nextline != NULL + && (*(p = skipwhite(sp->nextline)) == '\\' + || (p[0] == '"' && p[1] == '\\' && p[2] == ' '))) { garray_T ga; ga_init(&ga, (int)sizeof(char_u), 400); ga_concat(&ga, line); - ga_concat(&ga, p + 1); + if (*p == '\\') { + ga_concat(&ga, p + 1); + } for (;; ) { xfree(sp->nextline); sp->nextline = get_one_sourceline(sp); @@ -3417,15 +3422,16 @@ char_u *getsourceline(int c, void *cookie, int indent) break; } p = skipwhite(sp->nextline); - if (*p != '\\') { + if (*p == '\\') { + // Adjust the growsize to the current length to speed up + // concatenating many lines. + if (ga.ga_len > 400) { + ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len); + } + ga_concat(&ga, p + 1); + } else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ') { break; } - // Adjust the growsize to the current length to speed up - // concatenating many lines. - if (ga.ga_len > 400) { - ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len); - } - ga_concat(&ga, p + 1); } ga_append(&ga, NUL); xfree(line); diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index a99b7e9c0b..1850fb0cf1 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -38,3 +38,14 @@ func Test_mkdir_p() call delete('Xfile') call delete('Xmkdir', 'rf') endfunc + +func Test_line_continuation() + let array = [5, + "\ ignore this + \ 6, + "\ more to ignore + "\ more moreto ignore + \ ] + "\ and some more + call assert_equal([5, 6], array) +endfunc |