Patch 8.1.2233
Problem: Cannot get the Vim command line arguments.
Solution: Add v:argv. (Dmitri Vereshchagin, closes #1322)
Files: runtime/doc/eval.txt, src/evalvars.c, src/vim.h,
src/proto/
evalvars.pro, src/main.c, src/testdir/test_startup.vim
*** ../vim-8.1.2232/runtime/doc/eval.txt 2019-10-27 05:12:38.280773740 +0100
--- runtime/doc/eval.txt 2019-10-29 03:32:16.570868039 +0100
***************
*** 1662,1667 ****
--- 1662,1671 ----
*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.
***************
*** 3031,3036 ****
--- 3038,3044 ----
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|
*** ../vim-8.1.2232/src/evalvars.c 2019-10-16 23:34:38.614482577 +0200
--- src/evalvars.c 2019-10-29 03:29:07.787766237 +0100
***************
*** 143,148 ****
--- 143,149 ----
{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
***************
*** 2086,2091 ****
--- 2087,2113 ----
}
/*
+ * 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.
*/
void
*** ../vim-8.1.2232/src/vim.h 2019-10-27 22:54:24.583870611 +0100
--- src/vim.h 2019-10-29 03:22:49.353434642 +0100
***************
*** 1990,1996 ****
#define VV_EVENT 90
#define VV_VERSIONLONG 91
#define VV_ECHOSPACE 92
! #define VV_LEN 93 // number of v: vars
// used for v_number in VAR_SPECIAL
#define VVAL_FALSE 0L
--- 1990,1997 ----
#define VV_EVENT 90
#define VV_VERSIONLONG 91
#define VV_ECHOSPACE 92
! #define VV_ARGV 93
! #define VV_LEN 94 // number of v: vars
// used for v_number in VAR_SPECIAL
#define VVAL_FALSE 0L
*** ../vim-8.1.2232/src/evalvars.c 2019-10-16 23:34:38.614482577 +0200
--- src/evalvars.c 2019-10-29 03:29:07.787766237 +0100
***************
*** 143,148 ****
--- 143,149 ----
{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
***************
*** 2086,2091 ****
--- 2087,2113 ----
}
/*
+ * 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.
*/
void
*** ../vim-8.1.2232/src/proto/
evalvars.pro 2019-09-05 22:33:23.268963478 +0200
--- src/proto/
evalvars.pro 2019-10-29 03:29:50.879575749 +0100
***************
*** 41,46 ****
--- 41,47 ----
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);
*** ../vim-8.1.2232/src/main.c 2019-10-24 22:32:27.692284767 +0200
--- src/main.c 2019-10-29 03:28:24.427957836 +0100
***************
*** 1009,1015 ****
TIME_MSG("inits 1");
#ifdef FEAT_EVAL
! set_lang_var(); /* set v:lang and v:ctype */
#endif
#ifdef FEAT_SIGNS
--- 1009,1019 ----
TIME_MSG("inits 1");
#ifdef FEAT_EVAL
! // set v:lang and v:ctype
! set_lang_var();
!
! // set v:argv
! set_argv_var(paramp->argv, paramp->argc);
#endif
#ifdef FEAT_SIGNS
*** ../vim-8.1.2232/src/testdir/test_startup.vim 2019-10-05 12:09:21.258785431 +0200
--- src/testdir/test_startup.vim 2019-10-29 04:07:25.941347543 +0100
***************
*** 671,673 ****
--- 671,685 ----
" 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
*** ../vim-8.1.2232/src/version.c 2019-10-29 00:46:43.874173757 +0100
--- src/version.c 2019-10-29 04:10:55.936869255 +0100
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 2233,
/**/
--
Often you're less important than your furniture. If you think about it, you
can get fired but your furniture stays behind, gainfully employed at the
company that didn't need _you_ anymore.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///