summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-09 13:27:59 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-09 13:27:59 +0100
commit9132426334a8c7e159db93ec1b08ed61ac600aae (patch)
treedf075b01d29282377b71718766e9182f3e209f36
parent0dc2fd307ffc223cf010d1fdea6e3d5c4524d43c (diff)
patch 9.0.0423: "for" and "while" not recognized after :vim9cmd and :legacyv9.0.0423
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.
-rw-r--r--src/ex_docmd.c5
-rw-r--r--src/testdir/Make_all.mak2
-rw-r--r--src/testdir/test_cmdmods.vim35
-rw-r--r--src/testdir/test_eval_stuff.vim9
-rw-r--r--src/version.c2
5 files changed, 52 insertions, 1 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 0b6b217121..0024c99c63 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2888,7 +2888,7 @@ parse_command_modifiers(
switch (*p)
{
- // When adding an entry, also modify cmd_exists().
+ // When adding an entry, also modify cmdmods[].
case 'a': if (!checkforcmd_noparen(&eap->cmd, "aboveleft", 3))
break;
cmod->cmod_split |= WSP_ABOVE;
@@ -3958,11 +3958,13 @@ static struct cmdmod
{"confirm", 4, FALSE},
{"filter", 4, FALSE},
{"hide", 3, FALSE},
+ {"horizontal", 3, FALSE},
{"keepalt", 5, FALSE},
{"keepjumps", 5, FALSE},
{"keepmarks", 3, FALSE},
{"keeppatterns", 5, FALSE},
{"leftabove", 5, FALSE},
+ {"legacy", 3, FALSE},
{"lockmarks", 3, FALSE},
{"noautocmd", 3, FALSE},
{"noswapfile", 3, FALSE},
@@ -3974,6 +3976,7 @@ static struct cmdmod
{"unsilent", 3, FALSE},
{"verbose", 4, TRUE},
{"vertical", 4, FALSE},
+ {"vim9cmd", 4, FALSE},
};
/*
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index dbda7e15f3..d7abcb5a48 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -87,6 +87,7 @@ NEW_TESTS = \
test_clientserver \
test_close_count \
test_cmdline \
+ test_cmdmods \
test_cmdwin \
test_command_count \
test_comments \
@@ -346,6 +347,7 @@ NEW_TESTS_RES = \
test_clientserver.res \
test_close_count.res \
test_cmdline.res \
+ test_cmdmods.res \
test_cmdwin.res \
test_command_count.res \
test_comments.res \
diff --git a/src/testdir/test_cmdmods.vim b/src/testdir/test_cmdmods.vim
new file mode 100644
index 0000000000..eb6dff1cee
--- /dev/null
+++ b/src/testdir/test_cmdmods.vim
@@ -0,0 +1,35 @@
+" Test for all comand modifiers in
+
+def Test_cmdmods_array()
+ # Get all the command modifiers from ex_cmds.h.
+ var lines = readfile('../ex_cmds.h')->filter((_, l) => l =~ 'ex_wrongmodifier,')
+ var cmds = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
+
+ # :hide is both a command and a modifier
+ cmds->extend(['hide'])
+
+ # Get the entries of cmdmods[] in ex_docmd.c
+ edit ../ex_docmd.c
+ var top = search('^} cmdmods[') + 1
+ var bot = search('^};') - 1
+ lines = getline(top, bot)
+ var mods = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
+
+ # Check the lists are equal. Convert them to a dict to get a clearer error
+ # message.
+ var cmds_dict = {}
+ for v in cmds
+ cmds_dict[v] = 1
+ endfor
+ var mods_dict = {}
+ for v in mods
+ mods_dict[v] = 1
+ endfor
+ assert_equal(cmds_dict, mods_dict)
+
+ bwipe!
+enddef
+
+
+" vim: shiftwidth=2 sts=2 expandtab
+
diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim
index 0081d89a52..7d8421b725 100644
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -146,6 +146,15 @@ func Test_for_over_null_string()
let &enc = save_enc
endfunc
+func Test_for_with_modifier()
+ " this checks has_loop_cmd() works with a modifier
+ let result = []
+ vim9cmd for i in range(3)
+ call extend(result, [i])
+ endfor
+ call assert_equal([0, 1, 2], result)
+endfunc
+
func Test_for_invalid_line_count()
let lines =<< trim END
111111111111111111111111 for line in ['one']
diff --git a/src/version.c b/src/version.c
index fe87dabfcc..445ac6dde5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 423,
+/**/
422,
/**/
421,