0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2012-03-07 19:18:23 +01:00
parent 552ac13d55
commit 146e9c3886
5 changed files with 72 additions and 17 deletions

View File

@@ -1746,7 +1746,8 @@ exists( {expr}) Number TRUE if {expr} exists
extend( {expr1}, {expr2} [, {expr3}]) extend( {expr1}, {expr2} [, {expr3}])
List/Dict insert items of {expr2} into {expr1} List/Dict insert items of {expr2} into {expr1}
exp( {expr}) Float exponential of {expr} exp( {expr}) Float exponential of {expr}
expand( {expr} [, {flag}]) String expand special keywords in {expr} expand( {expr} [, {nosuf} [, {list}]])
any expand special keywords in {expr}
feedkeys( {string} [, {mode}]) Number add key sequence to typeahead buffer feedkeys( {string} [, {mode}]) Number add key sequence to typeahead buffer
filereadable( {file}) Number TRUE if {file} is a readable file filereadable( {file}) Number TRUE if {file} is a readable file
filewritable( {file}) Number TRUE if {file} is a writable file filewritable( {file}) Number TRUE if {file} is a writable file
@@ -1800,7 +1801,8 @@ gettabwinvar( {tabnr}, {winnr}, {name})
getwinposx() Number X coord in pixels of GUI Vim window getwinposx() Number X coord in pixels of GUI Vim window
getwinposy() Number Y coord in pixels of GUI Vim window getwinposy() Number Y coord in pixels of GUI Vim window
getwinvar( {nr}, {varname}) any variable {varname} in window {nr} getwinvar( {nr}, {varname}) any variable {varname} in window {nr}
glob( {expr} [, {flag}]) String expand file wildcards in {expr} glob( {expr} [, {nosuf} [, {list}]])
any expand file wildcards in {expr}
globpath( {path}, {expr} [, {flag}]) globpath( {path}, {expr} [, {flag}])
String do glob({expr}) for all dirs in {path} String do glob({expr}) for all dirs in {path}
has( {feature}) Number TRUE if feature {feature} supported has( {feature}) Number TRUE if feature {feature} supported
@@ -2802,10 +2804,10 @@ expand({expr} [, {flag}]) *expand()*
When {expr} does not start with '%', '#' or '<', it is When {expr} does not start with '%', '#' or '<', it is
expanded like a file name is expanded on the command line. expanded like a file name is expanded on the command line.
'suffixes' and 'wildignore' are used, unless the optional 'suffixes' and 'wildignore' are used, unless the optional
{flag} argument is given and it is non-zero. Names for {nosuf} argument is given and it is non-zero.
non-existing files are included. The "**" item can be used to Names for non-existing files are included. The "**" item can
search in a directory tree. For example, to find all "README" be used to search in a directory tree. For example, to find
files in the current directory and below: > all "README" files in the current directory and below: >
:echo expand("**/README") :echo expand("**/README")
< <
Expand() can also be used to expand variables and environment Expand() can also be used to expand variables and environment

View File

@@ -7852,7 +7852,7 @@ static struct fst
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
{"exp", 1, 1, f_exp}, {"exp", 1, 1, f_exp},
#endif #endif
{"expand", 1, 2, f_expand}, {"expand", 1, 3, f_expand},
{"extend", 2, 3, f_extend}, {"extend", 2, 3, f_extend},
{"feedkeys", 1, 2, f_feedkeys}, {"feedkeys", 1, 2, f_feedkeys},
{"file_readable", 1, 1, f_filereadable}, /* obsolete */ {"file_readable", 1, 1, f_filereadable}, /* obsolete */
@@ -7903,7 +7903,7 @@ static struct fst
{"getwinposx", 0, 0, f_getwinposx}, {"getwinposx", 0, 0, f_getwinposx},
{"getwinposy", 0, 0, f_getwinposy}, {"getwinposy", 0, 0, f_getwinposy},
{"getwinvar", 2, 2, f_getwinvar}, {"getwinvar", 2, 2, f_getwinvar},
{"glob", 1, 2, f_glob}, {"glob", 1, 3, f_glob},
{"globpath", 2, 3, f_globpath}, {"globpath", 2, 3, f_globpath},
{"has", 1, 1, f_has}, {"has", 1, 1, f_has},
{"has_key", 2, 2, f_has_key}, {"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; int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
expand_T xpc; expand_T xpc;
int error = FALSE; int error = FALSE;
char_u *result;
rettv->v_type = VAR_STRING; 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]); s = get_tv_string(&argvars[0]);
if (*s == '%' || *s == '#' || *s == '<') if (*s == '%' || *s == '#' || *s == '<')
{ {
++emsg_off; ++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; --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 else
{ {
@@ -10041,7 +10060,18 @@ f_expand(argvars, rettv)
xpc.xp_context = EXPAND_FILES; xpc.xp_context = EXPAND_FILES;
if (p_wic) if (p_wic)
options += WILD_ICASE; 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 else
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
@@ -11833,19 +11863,39 @@ f_glob(argvars, rettv)
int error = FALSE; int error = FALSE;
/* When the optional second argument is non-zero, don't remove matches /* When the optional second argument is non-zero, don't remove matches
* for 'wildignore' and don't put matches for 'suffixes' at the end. */ * 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;
rettv->v_type = VAR_STRING; 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) if (!error)
{ {
ExpandInit(&xpc); ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES; xpc.xp_context = EXPAND_FILES;
if (p_wic) if (p_wic)
options += WILD_ICASE; 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); 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 else
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;

View File

@@ -3461,6 +3461,7 @@ nextwild(xp, type, options)
* mode = WILD_PREV: use previous match in multiple match, wrap to first * mode = WILD_PREV: use previous match in multiple match, wrap to first
* mode = WILD_ALL: return all matches concatenated * mode = WILD_ALL: return all matches concatenated
* mode = WILD_LONGEST: return longest matched part * mode = WILD_LONGEST: return longest matched part
* mode = WILD_ALL_KEEP: get all matches, keep matches
* *
* options = WILD_LIST_NOTFOUND: list entries without a match * options = WILD_LIST_NOTFOUND: list entries without a match
* options = WILD_HOME_REPLACE: do home_replace() for buffer names * options = WILD_HOME_REPLACE: do home_replace() for buffer names
@@ -3584,7 +3585,8 @@ ExpandOne(xp, str, orig, options, mode)
/* /*
* Check for matching suffixes in file names. * Check for matching suffixes in file names.
*/ */
if (mode != WILD_ALL && mode != WILD_LONGEST) if (mode != WILD_ALL && mode != WILD_ALL_KEEP
&& mode != WILD_LONGEST)
{ {
if (xp->xp_numfiles) if (xp->xp_numfiles)
non_suf_match = xp->xp_numfiles; non_suf_match = xp->xp_numfiles;

View File

@@ -715,7 +715,7 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/ /**/
464, 465,
/**/ /**/
464, 464,
/**/ /**/

View File

@@ -794,6 +794,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
#define WILD_PREV 5 #define WILD_PREV 5
#define WILD_ALL 6 #define WILD_ALL 6
#define WILD_LONGEST 7 #define WILD_LONGEST 7
#define WILD_ALL_KEEP 8
#define WILD_LIST_NOTFOUND 1 #define WILD_LIST_NOTFOUND 1
#define WILD_HOME_REPLACE 2 #define WILD_HOME_REPLACE 2