Skip to content

Commit 9132426

Browse files
committed
patch 9.0.0423: "for" and "while" not recognized after :vim9cmd and :legacy
Problem: "for" and "while" not recognized after :vim9cmd and :legacy. (Emanuele Torre) Solution: Recognize all the command modifiers. (closes #11087) Add a test to check the list of modifiers.
1 parent 0dc2fd3 commit 9132426

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/ex_docmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,7 @@ parse_command_modifiers(
28882888

28892889
switch (*p)
28902890
{
2891-
// When adding an entry, also modify cmd_exists().
2891+
// When adding an entry, also modify cmdmods[].
28922892
case 'a': if (!checkforcmd_noparen(&eap->cmd, "aboveleft", 3))
28932893
break;
28942894
cmod->cmod_split |= WSP_ABOVE;
@@ -3958,11 +3958,13 @@ static struct cmdmod
39583958
{"confirm", 4, FALSE},
39593959
{"filter", 4, FALSE},
39603960
{"hide", 3, FALSE},
3961+
{"horizontal", 3, FALSE},
39613962
{"keepalt", 5, FALSE},
39623963
{"keepjumps", 5, FALSE},
39633964
{"keepmarks", 3, FALSE},
39643965
{"keeppatterns", 5, FALSE},
39653966
{"leftabove", 5, FALSE},
3967+
{"legacy", 3, FALSE},
39663968
{"lockmarks", 3, FALSE},
39673969
{"noautocmd", 3, FALSE},
39683970
{"noswapfile", 3, FALSE},
@@ -3974,6 +3976,7 @@ static struct cmdmod
39743976
{"unsilent", 3, FALSE},
39753977
{"verbose", 4, TRUE},
39763978
{"vertical", 4, FALSE},
3979+
{"vim9cmd", 4, FALSE},
39773980
};
39783981

39793982
/*

src/testdir/Make_all.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ NEW_TESTS = \
8787
test_clientserver \
8888
test_close_count \
8989
test_cmdline \
90+
test_cmdmods \
9091
test_cmdwin \
9192
test_command_count \
9293
test_comments \
@@ -346,6 +347,7 @@ NEW_TESTS_RES = \
346347
test_clientserver.res \
347348
test_close_count.res \
348349
test_cmdline.res \
350+
test_cmdmods.res \
349351
test_cmdwin.res \
350352
test_command_count.res \
351353
test_comments.res \

src/testdir/test_cmdmods.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
" Test for all comand modifiers in
2+
3+
def Test_cmdmods_array()
4+
# Get all the command modifiers from ex_cmds.h.
5+
var lines = readfile('../ex_cmds.h')->filter((_, l) => l =~ 'ex_wrongmodifier,')
6+
var cmds = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
7+
8+
# :hide is both a command and a modifier
9+
cmds->extend(['hide'])
10+
11+
# Get the entries of cmdmods[] in ex_docmd.c
12+
edit ../ex_docmd.c
13+
var top = search('^} cmdmods[') + 1
14+
var bot = search('^};') - 1
15+
lines = getline(top, bot)
16+
var mods = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
17+
18+
# Check the lists are equal. Convert them to a dict to get a clearer error
19+
# message.
20+
var cmds_dict = {}
21+
for v in cmds
22+
cmds_dict[v] = 1
23+
endfor
24+
var mods_dict = {}
25+
for v in mods
26+
mods_dict[v] = 1
27+
endfor
28+
assert_equal(cmds_dict, mods_dict)
29+
30+
bwipe!
31+
enddef
32+
33+
34+
" vim: shiftwidth=2 sts=2 expandtab
35+

src/testdir/test_eval_stuff.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ func Test_for_over_null_string()
146146
let &enc = save_enc
147147
endfunc
148148

149+
func Test_for_with_modifier()
150+
" this checks has_loop_cmd() works with a modifier
151+
let result = []
152+
vim9cmd for i in range(3)
153+
call extend(result, [i])
154+
endfor
155+
call assert_equal([0, 1, 2], result)
156+
endfunc
157+
149158
func Test_for_invalid_line_count()
150159
let lines =<< trim END
151160
111111111111111111111111 for line in ['one']

src/version.c

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

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
423,
706708
/**/
707709
422,
708710
/**/

0 commit comments

Comments
 (0)