]> granicus.if.org Git - vim/commitdiff
patch 8.0.0654: no warning for text after :endfunction v8.0.0654
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2017 17:12:10 +0000 (19:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2017 17:12:10 +0000 (19:12 +0200)
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.

runtime/doc/eval.txt
src/testdir/test_vimscript.vim
src/userfunc.c
src/version.c

index dec960bb789f7101b7f96ed83e95be2ba0877ac4..19eb6730395e9143d14fbb398bfe66d322183b69 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 8.0.  Last change: 2017 Jun 13
+*eval.txt*     For Vim version 8.0.  Last change: 2017 Jun 22
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -8764,18 +8764,32 @@ See |:verbose-cmd| for more information.
                        implies that the effect of |:nohlsearch| is undone
                        when the function returns.
 
-                                       *:endf* *:endfunction* *E126* *E193*
-:endf[unction]         The end of a function definition.  Must be on a line
-                       by its own, without other commands.
+                               *:endf* *:endfunction* *E126* *E193* *E946*
+:endf[unction] [argument]
+                       The end of a function definition.  Best is to put it
+                       on a line by its own, without [argument].
+
+                       [argument] can be:
+                               | command       command to execute next
+                               \n command      command to execute next
+                               " comment       always ignored
+                               anything else   ignored, unless 'verbose' is
+                                               non-zero
+                       The support for a following command was added in Vim
+                       8.0.0654, before that any argument was silently
+                       ignored.
 
                                *:delf* *:delfunction* *E130* *E131* *E933*
-:delf[unction] {name}  Delete function {name}.
+:delf[unction][!] {name}
+                       Delete function {name}.
                        {name} can also be a |Dictionary| entry that is a
                        |Funcref|: >
                                :delfunc dict.init
 <                      This will remove the "init" entry from "dict".  The
                        function is deleted if there are no more references to
                        it.
+                       With the ! there is no error if the function does not
+                       exist.
                                                        *:retu* *:return* *E133*
 :retu[rn] [expr]       Return from a function.  When "[expr]" is given, it is
                        evaluated and returned as the result of the function.
index f4d2cd03d537c55847a0199d3c95670f24c06fdf..6f5a73fb862a39932fecc784b9654eef15cfbe29 100644 (file)
@@ -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
index 859e6ebec08de97e7743da5e168b84f7d3001048..de089bb68de1fab81ea213aba143796d39dc198f 100644 (file)
@@ -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;
index 149a83f8827db2efb709bfb37665318bdf85ee22..1e7d6486185caab4b1a43851eb20d0a3fda2408e 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    654,
 /**/
     653,
 /**/