Mercurial > vim
changeset 23938:2a885d095bff v8.2.2511
patch 8.2.2511: Vim9: cannot use Vim9 script syntax in some places
Commit: https://github.com/vim/vim/commit/39f3b1411068ff187b4f9f482b2d6b2c1e7a7268
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 14 12:57:36 2021 +0100
patch 8.2.2511: Vim9: cannot use Vim9 script syntax in some places
Problem: Vim9: cannot use Vim9 script syntax in some places.
Solution: Add the :vim9cmd command modifier. Incompatible: Makes ":vim9"
mean ":vim9cmd" instead of ":vim9script".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 Feb 2021 13:00:04 +0100 |
parents | 0a317b1a93cd |
children | c0b1516010b6 |
files | runtime/doc/repeat.txt runtime/doc/vim9.txt src/errors.h src/ex_cmdidxs.h src/ex_cmds.h src/ex_docmd.c src/structs.h src/testdir/dumps/Test_wildmenu_1.dump src/testdir/dumps/Test_wildmenu_2.dump src/testdir/dumps/Test_wildmenu_3.dump src/testdir/dumps/Test_wildmenu_4.dump src/testdir/test_cmdline.vim src/testdir/test_quickfix.vim src/testdir/test_vim9_cmd.vim src/version.c |
diffstat | 15 files changed, 56 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -354,13 +354,15 @@ For writing a Vim script, see chapter 41 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
--- a/runtime/doc/vim9.txt +++ b/runtime/doc/vim9.txt @@ -51,6 +51,7 @@ The Vim9 script syntax and semantics are - 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 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*
--- a/src/errors.h +++ b/src/errors.h @@ -363,3 +363,5 @@ EXTERN char e_register_name_must_be_one_ 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"));
--- 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][ /* 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;
--- 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),
--- 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))
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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>")
--- 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
--- 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`