summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/repeat.txt4
-rw-r--r--runtime/doc/vim9.txt7
-rw-r--r--src/errors.h2
-rw-r--r--src/ex_cmdidxs.h12
-rw-r--r--src/ex_cmds.h3
-rw-r--r--src/ex_docmd.c15
-rw-r--r--src/structs.h1
-rw-r--r--src/testdir/dumps/Test_wildmenu_1.dump4
-rw-r--r--src/testdir/dumps/Test_wildmenu_2.dump4
-rw-r--r--src/testdir/dumps/Test_wildmenu_3.dump4
-rw-r--r--src/testdir/dumps/Test_wildmenu_4.dump2
-rw-r--r--src/testdir/test_cmdline.vim2
-rw-r--r--src/testdir/test_quickfix.vim2
-rw-r--r--src/testdir/test_vim9_cmd.vim10
-rw-r--r--src/version.c2
15 files changed, 56 insertions, 18 deletions
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt
index 195a2025a..60ef9c1a0 100644
--- a/runtime/doc/repeat.txt
+++ b/runtime/doc/repeat.txt
@@ -354,13 +354,15 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
Vim version, or update Vim to a newer version. See
|vimscript-version| for what changed between versions.
-:vim9[script] [noclear] *:vim9* *:vim9script*
+:vim9s[cript] [noclear] *:vim9s* *:vim9script*
Marks a script file as containing |Vim9-script|
commands. Also see |vim9-namespace|.
Must be the first command in the file.
For [noclear] see |vim9-reload|.
Without the |+eval| feature this changes the syntax
for some commands.
+ See |:vim9cmd| for executing one command with Vim9
+ syntax and semantics.
*:scr* *:scriptnames*
:scr[iptnames] List all sourced script names, in the order they were
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index 804a98ad9..beec86fd3 100644
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -51,6 +51,7 @@ The Vim9 script syntax and semantics are used in:
- a function defined with the `:def` command
- a script file where the first command is `vim9script`
- an autocommand defined in the context of the above
+- a command prefixed with the `vim9cmd` command modifier
When using `:function` in a Vim9 script file the legacy syntax is used, with
the highest |scriptversion|. However, this can be confusing and is therefore
@@ -60,6 +61,12 @@ Vim9 script and legacy Vim script can be mixed. There is no requirement to
rewrite old scripts, they keep working as before. You may want to use a few
`:def` functions for code that needs to be fast.
+ *:vim9* *:vim9cmd*
+:vim9[cmd] {cmd}
+ Execute {cmd} using Vim9 script syntax and semantics.
+ Useful when typing a command and in a legacy script or
+ function.
+
==============================================================================
2. Differences from legacy Vim script *vim9-differences*
diff --git a/src/errors.h b/src/errors.h
index 927e1ffde..05f90b14b 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -363,3 +363,5 @@ EXTERN char e_register_name_must_be_one_char_str[]
INIT(= N_("E1162: Register name must be one character: %s"));
EXTERN char e_variable_nr_type_mismatch_expected_str_but_got_str[]
INIT(= N_("E1163: Variable %d: type mismatch, expected %s but got %s"));
+EXTERN char e_vim9cmd_must_be_followed_by_command[]
+ INIT(= N_("E1164: vim9cmd must be followed by a command"));
diff --git a/src/ex_cmdidxs.h b/src/ex_cmdidxs.h
index 290e9fa6b..8afc44535 100644
--- a/src/ex_cmdidxs.h
+++ b/src/ex_cmdidxs.h
@@ -27,10 +27,10 @@ static const unsigned short cmdidxs1[26] =
/* t */ 458,
/* u */ 503,
/* v */ 514,
- /* w */ 534,
- /* x */ 548,
- /* y */ 558,
- /* z */ 559
+ /* w */ 535,
+ /* x */ 549,
+ /* y */ 559,
+ /* z */ 560
};
/*
@@ -62,11 +62,11 @@ static const unsigned char cmdidxs2[26][26] =
/* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 63, 64, 0, 65, 0 },
/* t */ { 2, 0, 19, 0, 24, 26, 0, 27, 0, 28, 0, 29, 33, 36, 38, 39, 0, 40, 42, 0, 43, 0, 0, 0, 0, 0 },
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- /* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 11, 14, 0, 0, 0, 0, 17, 0, 18, 0, 0, 0, 0, 0 },
+ /* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 12, 15, 0, 0, 0, 0, 18, 0, 19, 0, 0, 0, 0, 0 },
/* w */ { 2, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 0, 0, 12, 13, 0, 0, 0, 0 },
/* x */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 7, 0, 0, 8, 0, 0, 0, 0, 0 },
/* y */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
-static const int command_count = 574;
+static const int command_count = 575;
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index 01c615614..e82e91bb3 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -1679,6 +1679,9 @@ EXCMD(CMD_vimgrep, "vimgrep", ex_vimgrep,
EXCMD(CMD_vimgrepadd, "vimgrepadd", ex_vimgrep,
EX_RANGE|EX_BANG|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_TRLBAR|EX_XFILE|EX_LOCK_OK,
ADDR_OTHER),
+EXCMD(CMD_vim9cmd, "vim9cmd", ex_wrongmodifier,
+ EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_vim9script, "vim9script", ex_vim9script,
EX_WORD1|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 9409d7c5e..0bb5142d7 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1737,7 +1737,7 @@ do_one_cmd(
int starts_with_colon = FALSE;
#ifdef FEAT_EVAL
int may_have_range;
- int vim9script = in_vim9script();
+ int vim9script;
int did_set_expr_line = FALSE;
#endif
int sourcing = flags & DOCMD_VERBOSE;
@@ -1785,7 +1785,7 @@ do_one_cmd(
if (parse_command_modifiers(&ea, &errormsg, &cmdmod, FALSE) == FAIL)
goto doend;
apply_cmdmod(&cmdmod);
-
+ vim9script = in_vim9script();
after_modifier = ea.cmd;
#ifdef FEAT_EVAL
@@ -2933,6 +2933,17 @@ parse_command_modifiers(
cmod->cmod_split |= WSP_VERT;
continue;
}
+ if (checkforcmd(&eap->cmd, "vim9cmd", 4))
+ {
+ if (ends_excmd2(p, eap->cmd))
+ {
+ *errormsg =
+ _(e_vim9cmd_must_be_followed_by_command);
+ return FAIL;
+ }
+ cmod->cmod_flags |= CMOD_VIM9CMD;
+ continue;
+ }
if (!checkforcmd(&p, "verbose", 4))
break;
if (vim_isdigit(*eap->cmd))
diff --git a/src/structs.h b/src/structs.h
index 550e53a2b..7bcbc389e 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -642,6 +642,7 @@ typedef struct
#define CMOD_LOCKMARKS 0x0800 // ":lockmarks"
#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
+#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
int cmod_split; // flags for win_split()
int cmod_tab; // > 0 when ":tab" was used
diff --git a/src/testdir/dumps/Test_wildmenu_1.dump b/src/testdir/dumps/Test_wildmenu_1.dump
index a11896958..76b930dfd 100644
--- a/src/testdir/dumps/Test_wildmenu_1.dump
+++ b/src/testdir/dumps/Test_wildmenu_1.dump
@@ -4,5 +4,5 @@
|~| @73
|~| @73
|~| @73
-|v+0#0000001#ffff4012|i|m|9|s|c|r|i|p|t| +3#0000000#ffffff0@1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @43
-|:+0&&|v|i|m|9|s|c|r|i|p|t> @63
+|v+0#0000001#ffff4012|i|m|9|c|m|d| +3#0000000#ffffff0@1|v|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
+|:+0&&|v|i|m|9|c|m|d> @66
diff --git a/src/testdir/dumps/Test_wildmenu_2.dump b/src/testdir/dumps/Test_wildmenu_2.dump
index 46b41ae07..17b6b0248 100644
--- a/src/testdir/dumps/Test_wildmenu_2.dump
+++ b/src/testdir/dumps/Test_wildmenu_2.dump
@@ -4,5 +4,5 @@
|~| @73
|~| @73
|~| @73
-|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v+0#0000001#ffff4012|i|m|g|r|e|p| +3#0000000#ffffff0@1|v|i|m|g|r|e|p|a|d@1| @43
-|:+0&&|v|i|m|g|r|e|p> @66
+|v+3#0000000&|i|m|9|c|m|d| @1|v+0#0000001#ffff4012|i|m|9|s|c|r|i|p|t| +3#0000000#ffffff0@1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
+|:+0&&|v|i|m|9|s|c|r|i|p|t> @63
diff --git a/src/testdir/dumps/Test_wildmenu_3.dump b/src/testdir/dumps/Test_wildmenu_3.dump
index 44749367d..578c8f05b 100644
--- a/src/testdir/dumps/Test_wildmenu_3.dump
+++ b/src/testdir/dumps/Test_wildmenu_3.dump
@@ -4,5 +4,5 @@
|~| @73
|~| @73
|~| @73
-|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v+0#0000001#ffff4012|i|m|g|r|e|p|a|d@1| +3#0000000#ffffff0@43
-|:+0&&|v|i|m|g|r|e|p|a|d@1> @63
+|v+3#0000000&|i|m|9|c|m|d| @1|v|i|m|9|s|c|r|i|p|t| @1|v+0#0000001#ffff4012|i|m|g|r|e|p| +3#0000000#ffffff0@1|v|i|m|g|r|e|p|a|d@1| @34
+|:+0&&|v|i|m|g|r|e|p> @66
diff --git a/src/testdir/dumps/Test_wildmenu_4.dump b/src/testdir/dumps/Test_wildmenu_4.dump
index 3703fd529..4b16a3768 100644
--- a/src/testdir/dumps/Test_wildmenu_4.dump
+++ b/src/testdir/dumps/Test_wildmenu_4.dump
@@ -4,5 +4,5 @@
|~| @73
|~| @73
|~| @73
-|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @43
+|v+3#0000000&|i|m|9|c|m|d| @1|v|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
|:+0&&|v|i|m> @70
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 8faa25fe8..05d90f74d 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -119,7 +119,7 @@ func Test_wildmenu_screendump()
call term_sendkeys(buf, "\<Tab>")
call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
- call term_sendkeys(buf, "\<Tab>")
+ call term_sendkeys(buf, "\<Tab>\<Tab>")
call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
call term_sendkeys(buf, "\<Esc>")
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 6826acfd0..6ade32622 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -709,7 +709,7 @@ def Test_helpgrep_vim9_restore_cpo()
var dir = 'Xruntime/after'
&rtp ..= ',' .. dir
mkdir(dir .. '/ftplugin', 'p')
- writefile(['vim9'], dir .. '/ftplugin/qf.vim')
+ writefile(['vim9script'], dir .. '/ftplugin/qf.vim')
filetype plugin on
silent helpgrep grail
cwindow
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
index ef0a5fe2e..42c51b46c 100644
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -5,6 +5,16 @@ source vim9.vim
source term_util.vim
source view_util.vim
+def Test_vim9cmd()
+ var lines =<< trim END
+ vim9cmd var x = 123
+ let s:y = 'yes'
+ vim9c assert_equal(123, x)
+ vim9cm assert_equal('yes', y)
+ END
+ CheckScriptSuccess(lines)
+enddef
+
def Test_edit_wildcards()
var filename = 'Xtest'
edit `=filename`
diff --git a/src/version.c b/src/version.c
index 264df9bf1..c91182234 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2511,
+/**/
2510,
/**/
2509,