]> granicus.if.org Git - vim/commitdiff
patch 8.0.0176: cannot use :change inside a function definition v8.0.0176
authorBram Moolenaar <Bram@vim.org>
Thu, 12 Jan 2017 21:20:54 +0000 (22:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 12 Jan 2017 21:20:54 +0000 (22:20 +0100)
Problem:    Using :change in between :function and :endfunction fails.
Solution:   Recognize :change inside a function. (ichizok, closes #1374)

src/testdir/test_viml.vim
src/userfunc.c
src/version.c

index 3a195ddc54b8143ba6b6e4211cb253f951c02a6c..cc2303b647278c4c5b6a322346eff092ba3550a4 100644 (file)
@@ -1238,6 +1238,77 @@ func Test_num64()
     call assert_equal(rng, sort(range(0x100000001, 0xFFFFffff, -1), 'N'))
 endfunc
 
+"-------------------------------------------------------------------------------
+" Test 95:  lines of :append, :change, :insert                     {{{1
+"-------------------------------------------------------------------------------
+
+function! DefineFunction(name, body)
+    let func = join(['function! ' . a:name . '()'] + a:body + ['endfunction'], "\n")
+    exec func
+endfunction
+
+func Test_script_lines()
+    " :append
+    try
+        call DefineFunction('T_Append', [
+                    \ 'append',
+                    \ 'py <<EOS',
+                    \ '.',
+                    \ ])
+    catch
+        call assert_false(1, "Can't define function")
+    endtry
+    try
+        call DefineFunction('T_Append', [
+                    \ 'append',
+                    \ 'abc',
+                    \ ])
+        call assert_false(1, "Shouldn't be able to define function")
+    catch
+        call assert_exception('Vim(function):E126: Missing :endfunction')
+    endtry
+
+    " :change
+    try
+        call DefineFunction('T_Change', [
+                    \ 'change',
+                    \ 'py <<EOS',
+                    \ '.',
+                    \ ])
+    catch
+        call assert_false(1, "Can't define function")
+    endtry
+    try
+        call DefineFunction('T_Change', [
+                    \ 'change',
+                    \ 'abc',
+                    \ ])
+        call assert_false(1, "Shouldn't be able to define function")
+    catch
+        call assert_exception('Vim(function):E126: Missing :endfunction')
+    endtry
+
+    " :insert
+    try
+        call DefineFunction('T_Insert', [
+                    \ 'insert',
+                    \ 'py <<EOS',
+                    \ '.',
+                    \ ])
+    catch
+        call assert_false(1, "Can't define function")
+    endtry
+    try
+        call DefineFunction('T_Insert', [
+                    \ 'insert',
+                    \ 'abc',
+                    \ ])
+        call assert_false(1, "Shouldn't be able to define function")
+    catch
+        call assert_exception('Vim(function):E126: Missing :endfunction')
+    endtry
+endfunc
+
 "-------------------------------------------------------------------------------
 " Modelines                                                                {{{1
 " vim: ts=8 sw=4 tw=80 fdm=marker
index 369d92ad60653f5cf63664962ab5cd9aeda423a9..372c9bb860f677659c180e99d66353a3f4e2686a 100644 (file)
@@ -2085,9 +2085,14 @@ ex_function(exarg_T *eap)
                }
            }
 
-           /* Check for ":append" or ":insert". */
+           /* Check for ":append", ":change", ":insert". */
            p = skip_range(p, NULL);
            if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
+                   || (p[0] == 'c'
+                       && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
+                               && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
+                                       && (STRNCMP(&p[3], "nge", 3) != 0
+                                           || !ASCII_ISALPHA(p[6])))))))
                    || (p[0] == 'i'
                        && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
                                && (!ASCII_ISALPHA(p[2]) || (p[2] == 's'))))))
index d4f2dfc5bc4811494cc984a01237001aa0e1d707..c7e47fa41c9795e6e59156cc6e4bd56d4d1f3e4f 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    176,
 /**/
     175,
 /**/