summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-06-22 19:12:10 +0200
committerBram Moolenaar <Bram@vim.org>2017-06-22 19:12:10 +0200
commit663bb2331626944cea156374858131fcd323b9e9 (patch)
treea6cc8157e602bbfc3903dec711f82db3bc8dcb56 /src
parentc768a208ca8e0e0fec900c18d5d9a593357ad793 (diff)
downloadvim-git-663bb2331626944cea156374858131fcd323b9e9.tar.gz
patch 8.0.0654: no warning for text after :endfunctionv8.0.0654
Problem: Text found after :endfunction is silently ignored. Solution: Give a warning if 'verbose' is set. When | or \n are used, execute the text as a command.
Diffstat (limited to 'src')
-rw-r--r--src/testdir/test_vimscript.vim27
-rw-r--r--src/userfunc.c8
-rw-r--r--src/version.c2
3 files changed, 37 insertions, 0 deletions
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index f4d2cd03d..6f5a73fb8 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1363,6 +1363,33 @@ func Test_bitwise_functions()
call assert_fails("call invert({})", 'E728:')
endfunc
+" Test trailing text after :endfunction {{{1
+func Test_endfunction_trailing()
+ call assert_false(exists('*Xtest'))
+
+ exe "func Xtest()\necho 'hello'\nendfunc\nlet done = 'yes'"
+ call assert_true(exists('*Xtest'))
+ call assert_equal('yes', done)
+ delfunc Xtest
+ unlet done
+
+ exe "func Xtest()\necho 'hello'\nendfunc|let done = 'yes'"
+ call assert_true(exists('*Xtest'))
+ call assert_equal('yes', done)
+ delfunc Xtest
+ unlet done
+
+ set verbose=1
+ exe "func Xtest()\necho 'hello'\nendfunc \" garbage"
+ call assert_true(exists('*Xtest'))
+ delfunc Xtest
+
+ call assert_fails("func Xtest()\necho 'hello'\nendfunc garbage", 'E946')
+ call assert_true(exists('*Xtest'))
+ delfunc Xtest
+ set verbose=0
+endfunc
+
"-------------------------------------------------------------------------------
" Modelines {{{1
" vim: ts=8 sw=4 tw=80 fdm=marker
diff --git a/src/userfunc.c b/src/userfunc.c
index 859e6ebec..de089bb68 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2130,6 +2130,14 @@ ex_function(exarg_T *eap)
/* Check for "endfunction". */
if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0)
{
+ if (*p == '|')
+ /* Another command follows. */
+ eap->nextcmd = vim_strsave(p + 1);
+ else if (line_arg != NULL && *skipwhite(line_arg) != NUL)
+ /* Another command follows. */
+ eap->nextcmd = line_arg;
+ else if (*p != NUL && *p != '"' && p_verbose > 0)
+ EMSG2((char_u *)_("E946: Text found after :endfunction: %s"), p);
if (line_arg == NULL)
vim_free(theline);
break;
diff --git a/src/version.c b/src/version.c
index 149a83f88..1e7d64861 100644
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 654,
+/**/
653,
/**/
652,