Skip to content

Commit 70bcd73

Browse files
committed
patch 8.0.0176: cannot use :change inside a function definition
Problem: Using :change in between :function and :endfunction fails. Solution: Recognize :change inside a function. (ichizok, closes #1374)
1 parent 972c3b8 commit 70bcd73

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

src/testdir/test_viml.vim

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,77 @@ func Test_num64()
12381238
call assert_equal(rng, sort(range(0x100000001, 0xFFFFffff, -1), 'N'))
12391239
endfunc
12401240

1241+
"-------------------------------------------------------------------------------
1242+
" Test 95: lines of :append, :change, :insert {{{1
1243+
"-------------------------------------------------------------------------------
1244+
1245+
function! DefineFunction(name, body)
1246+
let func = join(['function! ' . a:name . '()'] + a:body + ['endfunction'], "\n")
1247+
exec func
1248+
endfunction
1249+
1250+
func Test_script_lines()
1251+
" :append
1252+
try
1253+
call DefineFunction('T_Append', [
1254+
\ 'append',
1255+
\ 'py <<EOS',
1256+
\ '.',
1257+
\ ])
1258+
catch
1259+
call assert_false(1, "Can't define function")
1260+
endtry
1261+
try
1262+
call DefineFunction('T_Append', [
1263+
\ 'append',
1264+
\ 'abc',
1265+
\ ])
1266+
call assert_false(1, "Shouldn't be able to define function")
1267+
catch
1268+
call assert_exception('Vim(function):E126: Missing :endfunction')
1269+
endtry
1270+
1271+
" :change
1272+
try
1273+
call DefineFunction('T_Change', [
1274+
\ 'change',
1275+
\ 'py <<EOS',
1276+
\ '.',
1277+
\ ])
1278+
catch
1279+
call assert_false(1, "Can't define function")
1280+
endtry
1281+
try
1282+
call DefineFunction('T_Change', [
1283+
\ 'change',
1284+
\ 'abc',
1285+
\ ])
1286+
call assert_false(1, "Shouldn't be able to define function")
1287+
catch
1288+
call assert_exception('Vim(function):E126: Missing :endfunction')
1289+
endtry
1290+
1291+
" :insert
1292+
try
1293+
call DefineFunction('T_Insert', [
1294+
\ 'insert',
1295+
\ 'py <<EOS',
1296+
\ '.',
1297+
\ ])
1298+
catch
1299+
call assert_false(1, "Can't define function")
1300+
endtry
1301+
try
1302+
call DefineFunction('T_Insert', [
1303+
\ 'insert',
1304+
\ 'abc',
1305+
\ ])
1306+
call assert_false(1, "Shouldn't be able to define function")
1307+
catch
1308+
call assert_exception('Vim(function):E126: Missing :endfunction')
1309+
endtry
1310+
endfunc
1311+
12411312
"-------------------------------------------------------------------------------
12421313
" Modelines {{{1
12431314
" vim: ts=8 sw=4 tw=80 fdm=marker

src/userfunc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,9 +2085,14 @@ ex_function(exarg_T *eap)
20852085
}
20862086
}
20872087

2088-
/* Check for ":append" or ":insert". */
2088+
/* Check for ":append", ":change", ":insert". */
20892089
p = skip_range(p, NULL);
20902090
if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
2091+
|| (p[0] == 'c'
2092+
&& (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
2093+
&& (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
2094+
&& (STRNCMP(&p[3], "nge", 3) != 0
2095+
|| !ASCII_ISALPHA(p[6])))))))
20912096
|| (p[0] == 'i'
20922097
&& (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
20932098
&& (!ASCII_ISALPHA(p[2]) || (p[2] == 's'))))))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
176,
767769
/**/
768770
175,
769771
/**/

0 commit comments

Comments
 (0)