diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 34 | ||||
-rw-r--r-- | src/nvim/testdir/test_let.vim | 79 |
2 files changed, 95 insertions, 18 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9b12ca1e12..6d706939a1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21269,6 +21269,7 @@ void ex_function(exarg_T *eap) int indent; int nesting; char_u *skip_until = NULL; + char_u *trimmed = NULL; dictitem_T *v; funcdict_T fudi; static int func_nr = 0; /* number for nameless function */ @@ -21572,10 +21573,14 @@ void ex_function(exarg_T *eap) sourcing_lnum_off = 0; if (skip_until != NULL) { - /* between ":append" and "." and between ":python <<EOF" and "EOF" - * don't check for ":endfunc". */ - if (STRCMP(theline, skip_until) == 0) { - XFREE_CLEAR(skip_until); + // Between ":append" and "." and between ":python <<EOF" and "EOF" + // don't check for ":endfunc". + if (trimmed == NULL || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0) { + p = trimmed == NULL ? theline : theline + STRLEN(trimmed); + if (STRCMP(p, skip_until) == 0) { + XFREE_CLEAR(skip_until); + XFREE_CLEAR(trimmed); + } } } else { /* skip ':' and blanks*/ @@ -21674,6 +21679,27 @@ void ex_function(exarg_T *eap) else skip_until = vim_strsave(p); } + + // Check for ":let v =<< [trim] EOF" + arg = skipwhite(skiptowhite(p)); + arg = skipwhite(skiptowhite(arg)); + if (arg[0] == '=' && arg[1] == '<' && arg[2] =='<' + && ((p[0] == 'l' && p[1] == 'e' + && (!ASCII_ISALNUM(p[2]) + || (p[2] == 't' && !ASCII_ISALNUM(p[3])))))) { + // ":let v =<<" continues until a dot + p = skipwhite(arg + 3); + if (STRNCMP(p, "trim", 4) == 0) { + // Ignore leading white space. + p = skipwhite(p + 4); + trimmed = vim_strnsave(theline, (int)(skipwhite(theline) - theline)); + } + if (*p == NUL) { + skip_until = vim_strsave((char_u *)"."); + } else { + skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p)); + } + } } /* Add the line to the function. */ diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 9887fb531e..43f35e2b9d 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -141,6 +141,27 @@ func Test_let_varg_fail() call s:set_varg8([0]) endfunction +func Test_let_heredoc_fails() + call assert_fails('let v =<< marker', 'E991:') + + let text =<< trim END + func WrongSyntax() + let v =<< that there + endfunc + END + call writefile(text, 'XheredocFail') + call assert_fails('source XheredocFail', 'E126:') + call delete('XheredocFail') + + let text =<< trim END + func MissingEnd() + let v =<< END + endfunc + END + call writefile(text, 'XheredocWrong') + call assert_fails('source XheredocWrong', 'E126:') + call delete('XheredocWrong') +endfunc " Test for the setting a variable using the heredoc syntax func Test_let_heredoc() @@ -170,12 +191,12 @@ END END call assert_equal(['vim', '', 'end', ' END', 'END '], var3) - let var1 =<< trim END - Line1 - Line2 - Line3 - END - END + let var1 =<< trim END + Line1 + Line2 + Line3 + END + END call assert_equal(['Line1', ' Line2', "\tLine3", ' END'], var1) let var1 =<< trim @@ -183,15 +204,45 @@ END . call assert_equal([' Line1'], var1) - call assert_fails('let v =<< marker', 'E991:') - call assert_fails('call WrongSyntax()', 'E488:') - call assert_fails('call MissingEnd()', 'E990:') + " ignore "endfunc" + let var1 =<< END +something endfunc +END + call assert_equal(['something', 'endfunc'], var1) -func WrongSyntax() - let fail =<< that there -endfunc + " ignore "endfunc" with trim + let var1 =<< trim END + something + endfunc + END + call assert_equal(['something', 'endfunc'], var1) + + " ignore "python << xx" + let var1 =<<END +something +python << xx +END + call assert_equal(['something', 'python << xx'], var1) + + " ignore "python << xx" with trim + let var1 =<< trim END + something + python << xx + END + call assert_equal(['something', 'python << xx'], var1) -func MissingEnd() - let fail =<< END + " ignore "append" + let var1 =<< +something +app +. + call assert_equal(['something', 'app'], var1) + + " ignore "append" with trim + let var1 =<< trim + something + app + . + call assert_equal(['something', 'app'], var1) endfunc |