diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-10-29 04:16:57 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-10-29 04:16:57 +0100 |
commit | 69bf634858a2a75f2984e42b1e4017bc529a040a (patch) | |
tree | 1584b32f67463ec2b31ac858e5ada499a34967af /src | |
parent | 8b530c1ff91f07cf6b0289a536992b7dfbc86598 (diff) | |
download | vim-git-69bf634858a2a75f2984e42b1e4017bc529a040a.tar.gz |
patch 8.1.2233: cannot get the Vim command line argumentsv8.1.2233
Problem: Cannot get the Vim command line arguments.
Solution: Add v:argv. (Dmitri Vereshchagin, closes #1322)
Diffstat (limited to 'src')
-rw-r--r-- | src/evalvars.c | 22 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/normal.c | 2 | ||||
-rw-r--r-- | src/proto/evalvars.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_startup.vim | 12 | ||||
-rw-r--r-- | src/version.c | 4 | ||||
-rw-r--r-- | src/vim.h | 3 |
7 files changed, 47 insertions, 3 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index eb198fdf9..3aaae13b4 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -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 @@ -2086,6 +2087,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. */ void diff --git a/src/main.c b/src/main.c index 8001c3fbb..2ec5c2631 100644 --- a/src/main.c +++ b/src/main.c @@ -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 diff --git a/src/normal.c b/src/normal.c index 17db06a16..f2527e144 100644 --- a/src/normal.c +++ b/src/normal.c @@ -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) diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro index 691eec349..bb8b5a1c6 100644 --- a/src/proto/evalvars.pro +++ b/src/proto/evalvars.pro @@ -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); diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim index f10eabb79..358ca8171 100644 --- a/src/testdir/test_startup.vim +++ b/src/testdir/test_startup.vim @@ -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 diff --git a/src/version.c b/src/version.c index 99f15701b..0e92901b7 100644 --- a/src/version.c +++ b/src/version.c @@ -742,6 +742,10 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2233, +/**/ + 2232, +/**/ 2231, /**/ 2230, @@ -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 |