diff options
author | Bram Moolenaar <Bram@vim.org> | 2012-03-07 19:18:23 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2012-03-07 19:18:23 +0100 |
commit | 146e9c38866248ff92f6109c536bbe79744256f5 (patch) | |
tree | dc355606924b00ad8741b10056b742458ea506dc /src/eval.c | |
parent | 552ac13d55d3edd961c789dbff126d15fb51ac75 (diff) | |
download | vim-146e9c38866248ff92f6109c536bbe79744256f5.zip |
updated for version 7.3.465
Problem: Cannot get file name with newline from glob().
Solution: Add argument to glob() and expand() to indicate they must return a
list. (Christian Brabandt)
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/src/eval.c b/src/eval.c index 848c6670d..105642265 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7852,7 +7852,7 @@ static struct fst #ifdef FEAT_FLOAT {"exp", 1, 1, f_exp}, #endif - {"expand", 1, 2, f_expand}, + {"expand", 1, 3, f_expand}, {"extend", 2, 3, f_extend}, {"feedkeys", 1, 2, f_feedkeys}, {"file_readable", 1, 1, f_filereadable}, /* obsolete */ @@ -7903,7 +7903,7 @@ static struct fst {"getwinposx", 0, 0, f_getwinposx}, {"getwinposy", 0, 0, f_getwinposy}, {"getwinvar", 2, 2, f_getwinvar}, - {"glob", 1, 2, f_glob}, + {"glob", 1, 3, f_glob}, {"globpath", 2, 3, f_globpath}, {"has", 1, 1, f_has}, {"has_key", 2, 2, f_has_key}, @@ -10019,14 +10019,33 @@ f_expand(argvars, rettv) int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; expand_T xpc; int error = FALSE; + char_u *result; rettv->v_type = VAR_STRING; + if (argvars[1].v_type != VAR_UNKNOWN + && argvars[2].v_type != VAR_UNKNOWN + && get_tv_number_chk(&argvars[2], &error) + && !error) + { + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + } + s = get_tv_string(&argvars[0]); if (*s == '%' || *s == '#' || *s == '<') { ++emsg_off; - rettv->vval.v_string = eval_vars(s, s, &len, NULL, &errormsg, NULL); + result = eval_vars(s, s, &len, NULL, &errormsg, NULL); --emsg_off; + if (rettv->v_type == VAR_LIST) + { + if (rettv_list_alloc(rettv) != FAIL && result != NULL) + list_append_string(rettv->vval.v_list, result, -1); + else + vim_free(result); + } + else + rettv->vval.v_string = result; } else { @@ -10041,7 +10060,18 @@ f_expand(argvars, rettv) xpc.xp_context = EXPAND_FILES; if (p_wic) options += WILD_ICASE; - rettv->vval.v_string = ExpandOne(&xpc, s, NULL, options, WILD_ALL); + if (rettv->v_type == VAR_STRING) + rettv->vval.v_string = ExpandOne(&xpc, s, NULL, + options, WILD_ALL); + else if (rettv_list_alloc(rettv) != FAIL) + { + int i; + + ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP); + for (i = 0; i < xpc.xp_numfiles; i++) + list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); + ExpandCleanup(&xpc); + } } else rettv->vval.v_string = NULL; @@ -11833,19 +11863,39 @@ f_glob(argvars, rettv) int error = FALSE; /* When the optional second argument is non-zero, don't remove matches - * for 'wildignore' and don't put matches for 'suffixes' at the end. */ - if (argvars[1].v_type != VAR_UNKNOWN - && get_tv_number_chk(&argvars[1], &error)) - options |= WILD_KEEP_ALL; + * for 'wildignore' and don't put matches for 'suffixes' at the end. */ rettv->v_type = VAR_STRING; + if (argvars[1].v_type != VAR_UNKNOWN) + { + if (get_tv_number_chk(&argvars[1], &error)) + options |= WILD_KEEP_ALL; + if (argvars[2].v_type != VAR_UNKNOWN + && get_tv_number_chk(&argvars[2], &error)) + { + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + } + } if (!error) { ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; if (p_wic) options += WILD_ICASE; - rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]), + if (rettv->v_type == VAR_STRING) + rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]), NULL, options, WILD_ALL); + else if (rettv_list_alloc(rettv) != FAIL) + { + int i; + + ExpandOne(&xpc, get_tv_string(&argvars[0]), + NULL, options, WILD_ALL_KEEP); + for (i = 0; i < xpc.xp_numfiles; i++) + list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); + + ExpandCleanup(&xpc); + } } else rettv->vval.v_string = NULL; |