]> granicus.if.org Git - vim/commitdiff
patch 8.2.2511: Vim9: cannot use Vim9 script syntax in some places v8.2.2511
authorBram Moolenaar <Bram@vim.org>
Sun, 14 Feb 2021 11:57:36 +0000 (12:57 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 Feb 2021 11:57:36 +0000 (12:57 +0100)
Problem:    Vim9: cannot use Vim9 script syntax in some places.
Solution:   Add the :vim9cmd command modifier. Incompatible: Makes ":vim9"
            mean ":vim9cmd" instead of ":vim9script".

15 files changed:
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

index 195a2025a5e206b554b638df2c8a47773b5b9e03..60ef9c1a0067c81598985a3796d942ed5949a0a3 100644 (file)
@@ -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
index 804a98ad98aa6ba030cdbb3665bb8aa706fa6ae7..beec86fd3f94789b1bebd1208462c2adecaca268 100644 (file)
@@ -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*
index 927e1ffde9b3e378077547249ef006e735083858..05f90b14b1fe3bd61499a5a555ad87b46a814b7a 100644 (file)
@@ -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"));
index 290e9fa6b8f240aee75f9d802c83bcb94bfeca82..8afc445357d2770c77ab4dc60f71a7d3bdfb5e9f 100644 (file)
@@ -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;
index 01c6156147809ed7bd9db006bb4632cfce790d6d..e82e91bb374075061204e59c1a361b0b2542894b 100644 (file)
@@ -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),
index 9409d7c5e0502e0d54ece03f5f36c2a051ced35f..0bb5142d7d0c45c7a92b6067bd4979c6dc3ddd8d 100644 (file)
@@ -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))
index 550e53a2bcebe85bc498d8e2710be30d3bdd3699..7bcbc389e8361de6675cb9bda6569191a49f7218 100644 (file)
@@ -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
index a1189695845a0ef6803d5160b8a117931d1a947c..76b930dfdeb9b5067b5aa76ad6d52737320423f6 100644 (file)
@@ -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
index 46b41ae07560c3e33b9029b15d116a802a7a26ee..17b6b02487a8e109dea74ad8b2a255ac0aa62623 100644 (file)
@@ -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
index 44749367df75cae0473da5222efce3872fc6c3b5..578c8f05b7b644661cb948fb9b5a1d11a2143ac1 100644 (file)
@@ -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
index 3703fd5292a9d46954828dc165a5e0d931e5a408..4b16a3768c4570b6c091217e32d32f1179dd75a2 100644 (file)
@@ -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
index 8faa25fe8af70316c4f427bb89416fdd8adfcfbc..05d90f74d1bc502eb5d20f61e5fb385f4c507a86 100644 (file)
@@ -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>")
 
index 6826acfd05693fab3695a87026c06630b17f6bca..6ade32622685ca3aacb5806baeab5f19f382649e 100644 (file)
@@ -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
index ef0a5fe2e887ee79856d310e4396bc5e548721fb..42c51b46cdec358f1ae96332b4b17547a30da6e3 100644 (file)
@@ -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`
index 264df9bf11ffe05683d9016995b3fcea4b803a79..c9118223414ad74be33a05b1626cf0b8aa928fa2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2511,
 /**/
     2510,
 /**/