]> granicus.if.org Git - vim/commitdiff
patch 8.2.2052: Vim9: "edit +4 fname" gives an error v8.2.2052
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Nov 2020 19:12:11 +0000 (20:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Nov 2020 19:12:11 +0000 (20:12 +0100)
Problem:    Vim9: "edit +4 fname" gives an error. (Naruhiko Nishino)
Solution:   Allow using a range in the +cmd argument. (closes #7364)

src/ex_cmds.c
src/ex_docmd.c
src/proto/ex_docmd.pro
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim.h

index aa9fe9b0a0e836eba38d53f9a968096e21cf133f..44d8cd8500f200316cc98d715b0a6daa6a4ef305 100644 (file)
@@ -3123,7 +3123,7 @@ do_ecmd(
 #endif
 
     if (command != NULL)
-       do_cmdline(command, NULL, NULL, DOCMD_VERBOSE);
+       do_cmdline(command, NULL, NULL, DOCMD_VERBOSE|DOCMD_RANGEOK);
 
 #ifdef FEAT_KEYMAP
     if (curbuf->b_kmap_state & KEYMAP_INIT)
index 44e113d53b79aab250e405a10591cf007973afd8..582791af63227cc2eddfbc15278f70658309175e 100644 (file)
@@ -594,6 +594,17 @@ do_cmdline_cmd(char_u *cmd)
                                   DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
 }
 
+/*
+ * Execute the "+cmd" argument of "edit +cmd fname" and the like.
+ * This allows for using a range without ":" in Vim9 script.
+ */
+    int
+do_cmd_argument(char_u *cmd)
+{
+    return do_cmdline(cmd, NULL, NULL,
+                     DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED|DOCMD_RANGEOK);
+}
+
 /*
  * do_cmdline(): execute one Ex command line
  *
@@ -989,7 +1000,7 @@ do_cmdline(
         *    "cmdline_copy" can change, e.g. for '%' and '#' expansion.
         */
        ++recursive;
-       next_cmdline = do_one_cmd(&cmdline_copy, flags & DOCMD_VERBOSE,
+       next_cmdline = do_one_cmd(&cmdline_copy, flags,
 #ifdef FEAT_EVAL
                                &cstack,
 #endif
@@ -1685,7 +1696,8 @@ comment_start(char_u *p, int starts_with_colon UNUSED)
 /*
  * Execute one Ex command.
  *
- * If 'sourcing' is TRUE, the command will be included in the error message.
+ * If "flags" has DOCMD_VERBOSE, the command will be included in the error
+ * message.
  *
  * 1. skip comment lines and leading space
  * 2. handle command modifiers
@@ -1708,7 +1720,7 @@ comment_start(char_u *p, int starts_with_colon UNUSED)
     static char_u *
 do_one_cmd(
     char_u     **cmdlinep,
-    int                sourcing,
+    int                flags,
 #ifdef FEAT_EVAL
     cstack_T   *cstack,
 #endif
@@ -1731,6 +1743,7 @@ do_one_cmd(
     int                vim9script = in_vim9script();
     int                did_set_expr_line = FALSE;
 #endif
+    int                sourcing = flags & DOCMD_VERBOSE;
 
     CLEAR_FIELD(ea);
     ea.line1 = 1;
@@ -1794,7 +1807,7 @@ do_one_cmd(
 #ifdef FEAT_EVAL
     // In Vim9 script a colon is required before the range.  This may also be
     // after command modifiers.
-    if (vim9script)
+    if (vim9script && (flags & DOCMD_RANGEOK) == 0)
     {
        may_have_range = FALSE;
        for (p = ea.cmd; p >= *cmdlinep; --p)
@@ -5009,7 +5022,7 @@ ex_buffer(exarg_T *eap)
        else
            goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2);
        if (eap->do_ecmd_cmd != NULL)
-           do_cmdline_cmd(eap->do_ecmd_cmd);
+           do_cmd_argument(eap->do_ecmd_cmd);
     }
 }
 
@@ -5022,7 +5035,7 @@ ex_bmodified(exarg_T *eap)
 {
     goto_buffer(eap, DOBUF_MOD, FORWARD, (int)eap->line2);
     if (eap->do_ecmd_cmd != NULL)
-       do_cmdline_cmd(eap->do_ecmd_cmd);
+       do_cmd_argument(eap->do_ecmd_cmd);
 }
 
 /*
@@ -5037,7 +5050,7 @@ ex_bnext(exarg_T *eap)
 
     goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2);
     if (eap->do_ecmd_cmd != NULL)
-       do_cmdline_cmd(eap->do_ecmd_cmd);
+       do_cmd_argument(eap->do_ecmd_cmd);
 }
 
 /*
@@ -5054,7 +5067,7 @@ ex_bprevious(exarg_T *eap)
 
     goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2);
     if (eap->do_ecmd_cmd != NULL)
-       do_cmdline_cmd(eap->do_ecmd_cmd);
+       do_cmd_argument(eap->do_ecmd_cmd);
 }
 
 /*
@@ -5071,7 +5084,7 @@ ex_brewind(exarg_T *eap)
 
     goto_buffer(eap, DOBUF_FIRST, FORWARD, 0);
     if (eap->do_ecmd_cmd != NULL)
-       do_cmdline_cmd(eap->do_ecmd_cmd);
+       do_cmd_argument(eap->do_ecmd_cmd);
 }
 
 /*
@@ -5086,7 +5099,7 @@ ex_blast(exarg_T *eap)
 
     goto_buffer(eap, DOBUF_LAST, BACKWARD, 0);
     if (eap->do_ecmd_cmd != NULL)
-       do_cmdline_cmd(eap->do_ecmd_cmd);
+       do_cmd_argument(eap->do_ecmd_cmd);
 }
 
 /*
@@ -6680,7 +6693,7 @@ do_exedit(
     else
     {
        if (eap->do_ecmd_cmd != NULL)
-           do_cmdline_cmd(eap->do_ecmd_cmd);
+           do_cmd_argument(eap->do_ecmd_cmd);
 #ifdef FEAT_TITLE
        n = curwin->w_arg_idx_invalid;
 #endif
index f8cb7ef68b0fc4775748e9d5fe3c7869ec2431f1..374d3996b34a2c49cb9ca20b0a0ce2c87836c4cd 100644 (file)
@@ -1,6 +1,7 @@
 /* ex_docmd.c */
 void do_exmode(int improved);
 int do_cmdline_cmd(char_u *cmd);
+int do_cmd_argument(char_u *cmd);
 int do_cmdline(char_u *cmdline, char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie, int flags);
 int getline_equal(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie, char_u *(*func)(int, void *, int, getline_opt_T));
 void *getline_cookie(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie);
index 97110ce5272d79f300a9ef2fe84d74deb8120cde..d0f9872caad94300e2dda121652599484fc664ca 100644 (file)
@@ -648,5 +648,17 @@ def Test_star_command()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_cmd_argument_without_colon()
+  new Xfile
+  setline(1, ['a', 'b', 'c', 'd'])
+  write
+  edit +3 %
+  assert_equal(3, getcurpos()[1])
+  edit +/a %
+  assert_equal(1, getcurpos()[1])
+  bwipe
+  delete('Xfile')
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 4c54fe580663da2c621047938ee8c53247dec0f9..c653cdc84f0f4e10bd2f8c5bb959f53a709963d1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2052,
 /**/
     2051,
 /**/
index d2e22fef0940f3a33a21a8ed167ac709130c68a0..6dcc509aa15c36a245b281733410590629c247ff 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1043,6 +1043,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define DOCMD_KEYTYPED 0x08    // don't reset KeyTyped
 #define DOCMD_EXCRESET 0x10    // reset exception environment (for debugging)
 #define DOCMD_KEEPLINE  0x20   // keep typed line for repeating with "."
+#define DOCMD_RANGEOK  0240    // can use a range without ":" in Vim9 script
 
 // flags for beginline()
 #define BL_WHITE       1       // cursor on first non-white in the line