vim-patch:9.0.0876: code is indented more than needed (#21805)

Problem:    Code is indented more than needed.
Solution:   Split ExpandEscape() in two. (Yegappan Lakshmanan, closes vim/vim#11539)

68353e5270

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq 2023-01-15 06:34:45 +08:00 committed by GitHub
parent f445096cc6
commit 4c8d707a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,18 +108,11 @@ static int sort_func_compare(const void *s1, const void *s2)
} }
/// Escape special characters in the cmdline completion matches. /// Escape special characters in the cmdline completion matches.
static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, int options) static void wildescape(expand_T *xp, const char *str, int numfiles, char **files)
{ {
int i;
char *p; char *p;
const int vse_what = xp->xp_context == EXPAND_BUFFERS ? VSE_BUFFER : VSE_NONE; const int vse_what = xp->xp_context == EXPAND_BUFFERS ? VSE_BUFFER : VSE_NONE;
// May change home directory back to "~"
if (options & WILD_HOME_REPLACE) {
tilde_replace(str, numfiles, files);
}
if (options & WILD_ESCAPE) {
if (xp->xp_context == EXPAND_FILES if (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_FILES_IN_PATH || xp->xp_context == EXPAND_FILES_IN_PATH
|| xp->xp_context == EXPAND_SHELLCMD || xp->xp_context == EXPAND_SHELLCMD
@ -127,23 +120,22 @@ static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, in
|| xp->xp_context == EXPAND_DIRECTORIES) { || xp->xp_context == EXPAND_DIRECTORIES) {
// Insert a backslash into a file name before a space, \, %, # // Insert a backslash into a file name before a space, \, %, #
// and wildmatch characters, except '~'. // and wildmatch characters, except '~'.
for (i = 0; i < numfiles; i++) { for (int i = 0; i < numfiles; i++) {
// for ":set path=" we need to escape spaces twice // for ":set path=" we need to escape spaces twice
if (xp->xp_backslash == XP_BS_THREE) { if (xp->xp_backslash == XP_BS_THREE) {
p = vim_strsave_escaped(files[i], " "); p = vim_strsave_escaped(files[i], " ");
xfree(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
#if defined(BACKSLASH_IN_FILENAME) #if defined(BACKSLASH_IN_FILENAME)
p = vim_strsave_escaped(files[i], (char_u *)" "); p = vim_strsave_escaped(files[i], " ");
xfree(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
#endif #endif
} }
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
p = vim_strsave_fnameescape((const char *)files[i], vse_what); p = vim_strsave_fnameescape(files[i], vse_what);
#else #else
p = vim_strsave_fnameescape((const char *)files[i], p = vim_strsave_fnameescape(files[i], xp->xp_shell ? VSE_SHELL : vse_what);
xp->xp_shell ? VSE_SHELL : vse_what);
#endif #endif
xfree(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
@ -164,12 +156,24 @@ static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, in
} else if (xp->xp_context == EXPAND_TAGS) { } else if (xp->xp_context == EXPAND_TAGS) {
// Insert a backslash before characters in a tag name that // Insert a backslash before characters in a tag name that
// would terminate the ":tag" command. // would terminate the ":tag" command.
for (i = 0; i < numfiles; i++) { for (int i = 0; i < numfiles; i++) {
p = vim_strsave_escaped(files[i], "\\|\""); p = vim_strsave_escaped(files[i], "\\|\"");
xfree(files[i]); xfree(files[i]);
files[i] = p; files[i] = p;
} }
} }
}
/// Escape special characters in the cmdline completion matches.
static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, int options)
{
// May change home directory back to "~"
if (options & WILD_HOME_REPLACE) {
tilde_replace(str, numfiles, files);
}
if (options & WILD_ESCAPE) {
wildescape(xp, str, numfiles, files);
} }
} }
@ -2644,9 +2648,12 @@ static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char
// Expand matches in one directory of $PATH. // Expand matches in one directory of $PATH.
int ret = expand_wildcards(1, &buf, numMatches, matches, flags); int ret = expand_wildcards(1, &buf, numMatches, matches, flags);
if (ret == OK) { if (ret != OK) {
return;
}
ga_grow(gap, *numMatches); ga_grow(gap, *numMatches);
{
for (int i = 0; i < *numMatches; i++) { for (int i = 0; i < *numMatches; i++) {
char *name = (*matches)[i]; char *name = (*matches)[i];
@ -2666,8 +2673,6 @@ static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char
xfree(name); xfree(name);
} }
xfree(*matches); xfree(*matches);
}
}
} }
/// Complete a shell command. /// Complete a shell command.
@ -3074,8 +3079,7 @@ static int wildmenu_process_key_filenames(CmdlineInfo *cclp, int key, expand_T *
j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j); j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j);
if (vim_ispathsep(cclp->cmdbuff[j]) if (vim_ispathsep(cclp->cmdbuff[j])
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
&& vim_strchr((const char_u *)" *?[{`$%#", cclp->cmdbuff[j + 1]) && vim_strchr(" *?[{`$%#", (uint8_t)cclp->cmdbuff[j + 1]) == NULL
== NULL
#endif #endif
) { ) {
if (found) { if (found) {