]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.2233: cannot get the Vim command line arguments v8.1.2233
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Oct 2019 03:16:57 +0000 (04:16 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Oct 2019 03:16:57 +0000 (04:16 +0100)
Problem:    Cannot get the Vim command line arguments.
Solution:   Add v:argv. (Dmitri Vereshchagin, closes #1322)

runtime/doc/eval.txt
src/evalvars.c
src/main.c
src/normal.c
src/proto/evalvars.pro
src/testdir/test_startup.vim
src/version.c
src/vim.h

index f50c8c5b879f545bafe67af8a635981e7addd800..30ec02d3c4ff380bcee2eba63655300769e9c6da 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 8.1.  Last change: 2019 Oct 26
+*eval.txt*     For Vim version 8.1.  Last change: 2019 Oct 29
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1662,6 +1662,10 @@ PREDEFINED VIM VARIABLES                 *vim-variable* *v:var* *v:*
                                                                *E963*
 Some variables can be set by the user, but the type cannot be changed.
 
+                                       *v:argv* *argv-variable*
+v:argv         The command line arguments Vim was invoked with.  This is a
+               list of strings.  The first item is the Vim command.
+
                                        *v:beval_col* *beval_col-variable*
 v:beval_col    The number of the column, over which the mouse pointer is.
                This is the byte index in the |v:beval_lnum| line.
@@ -3034,6 +3038,7 @@ argv([{nr} [, {winid}])
                the whole |arglist| is returned.
 
                The {winid} argument specifies the window ID, see |argc()|.
+               For the Vim command line arguments see |v:argv|.
 
 
 assert_ functions are documented here: |assert-functions-details|
index eb198fdf9f2f99f4e62c8be7f9db458c07bfd247..3aaae13b4577c60292fc0ec7ac04efaca09c76e4 100644 (file)
@@ -143,6 +143,7 @@ static struct vimvar
     {VV_NAME("event",           VAR_DICT), VV_RO},
     {VV_NAME("versionlong",     VAR_NUMBER), VV_RO},
     {VV_NAME("echospace",       VAR_NUMBER), VV_RO},
+    {VV_NAME("argv",            VAR_LIST), VV_RO},
 };
 
 // shorthand
@@ -2085,6 +2086,27 @@ set_vim_var_dict(int idx, dict_T *val)
     }
 }
 
+/*
+ * Set the v:argv list.
+ */
+    void
+set_argv_var(char **argv, int argc)
+{
+    list_T     *l = list_alloc();
+    int                i;
+
+    if (l == NULL)
+       getout(1);
+    l->lv_lock = VAR_FIXED;
+    for (i = 0; i < argc; ++i)
+    {
+       if (list_append_string(l, (char_u *)argv[i], -1) == FAIL)
+           getout(1);
+       l->lv_last->li_tv.v_lock = VAR_FIXED;
+    }
+    set_vim_var_list(VV_ARGV, l);
+}
+
 /*
  * Set v:register if needed.
  */
index 8001c3fbb7f3f74379c212a0d4a347d9b809ac38..2ec5c2631793898151828c8c7b9cbbdb650d8cad 100644 (file)
@@ -1009,7 +1009,11 @@ common_init(mparm_T *paramp)
     TIME_MSG("inits 1");
 
 #ifdef FEAT_EVAL
-    set_lang_var();            /* set v:lang and v:ctype */
+    // set v:lang and v:ctype
+    set_lang_var();
+
+    // set v:argv
+    set_argv_var(paramp->argv, paramp->argc);
 #endif
 
 #ifdef FEAT_SIGNS
index 17db06a16766ac27d28b195dad71768991b0ba37..f2527e144bdf733252e747edf21fdc6c58be5653 100644 (file)
@@ -5986,7 +5986,7 @@ nv_g_cmd(cmdarg_T *cap)
            oap->motion_type = MCHAR;
            oap->inclusive = FALSE;
            if (has_mbyte)
-               i = mb_string2cells(ptr, STRLEN(ptr));
+               i = mb_string2cells(ptr, (int)STRLEN(ptr));
            else
                i = (int)STRLEN(ptr);
            if (cap->count0 > 0 && cap->count0 <= 100)
index 691eec34923ca3ead79f70a7572f8a36cd68fe76..bb8b5a1c65fefff1e7df5bd972e73759e0c2c246 100644 (file)
@@ -41,6 +41,7 @@ void restore_vimvars(vimvars_save_T *vvsave);
 void set_vim_var_string(int idx, char_u *val, int len);
 void set_vim_var_list(int idx, list_T *val);
 void set_vim_var_dict(int idx, dict_T *val);
+void set_argv_var(char **argv, int argc);
 void set_reg_var(int c);
 char_u *v_exception(char_u *oldval);
 char_u *v_throwpoint(char_u *oldval);
index f10eabb798698fb333eafc10bcb15d5ede1310a2..358ca817185f3f05ff2adc3104b58cd5f02815ca 100644 (file)
@@ -671,3 +671,15 @@ func Test_start_with_tabs()
   " clean up
   call StopVimInTerminal(buf)
 endfunc
+
+func Test_v_argv()
+  " Can't catch the output of gvim.
+  CheckNotGui
+
+  let out = system(GetVimCommand() . ' -es -V1 -X arg1 --cmd "echo v:argv" --cmd q')
+  let list = out->split("', '")
+  call assert_match('vim', list[0])
+  let idx = index(list, 'arg1')
+  call assert_true(idx > 2)
+  call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
+endfunc
index 99f15701b5a8dfbc01bbea4ba7d6edd2d8960b09..0e92901b7d35a2cfb1756c18a1d6be1eca83e05b 100644 (file)
@@ -741,6 +741,10 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2233,
+/**/
+    2232,
 /**/
     2231,
 /**/
index 7b2aa5be5ba1e6333102f085015f8d5e20374d66..de5873c1b124b6ee267f25e4921b810b3b70c8d8 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1990,7 +1990,8 @@ typedef int sock_T;
 #define VV_EVENT       90
 #define VV_VERSIONLONG 91
 #define VV_ECHOSPACE   92
-#define VV_LEN         93      // number of v: vars
+#define VV_ARGV                93
+#define VV_LEN         94      // number of v: vars
 
 // used for v_number in VAR_SPECIAL
 #define VVAL_FALSE     0L