summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-09-11 22:37:29 +0200
committerBram Moolenaar <Bram@vim.org>2018-09-11 22:37:29 +0200
commit67f8ab829911c7901c534ef2bf19cc34b622936f (patch)
tree6d56b95950cb18a0261c0e72d685b612dbb246db /runtime
parent25328e39d2a6e3ded82bf282a2e248ce7209f1b4 (diff)
downloadvim-git-67f8ab829911c7901c534ef2bf19cc34b622936f.tar.gz
patch 8.1.0369: continuation lines cannot contain commentsv8.1.0369
Problem: Continuation lines cannot contain comments. Solution: Support using "\ .
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/repeat.txt18
-rw-r--r--runtime/indent/vim.vim18
2 files changed, 28 insertions, 8 deletions
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt
index 55aed248b..c4b38a32d 100644
--- a/runtime/doc/repeat.txt
+++ b/runtime/doc/repeat.txt
@@ -465,6 +465,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
@@ -473,6 +483,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 8ebfa12ca..cd735c3a3 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