Problem: Cannot get the Vim command line arguments.
Solution: Add v:argv. (Dmitri Vereshchagin, closes #1322)
-*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
*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.
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|
{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
}
}
+/*
+ * 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.
*/
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
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)
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);
" 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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2233,
+/**/
+ 2232,
/**/
2231,
/**/
#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