aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cmdexpand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r--src/nvim/cmdexpand.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index c2469b6574..aef471a17b 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -156,8 +156,9 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files
// and wildmatch characters, except '~'.
for (int i = 0; i < numfiles; i++) {
// for ":set path=" we need to escape spaces twice
- if (xp->xp_backslash == XP_BS_THREE) {
- p = vim_strsave_escaped(files[i], " ");
+ if (xp->xp_backslash & XP_BS_THREE) {
+ char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " ";
+ p = vim_strsave_escaped(files[i], pat);
xfree(files[i]);
files[i] = p;
#if defined(BACKSLASH_IN_FILENAME)
@@ -165,6 +166,14 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files
xfree(files[i]);
files[i] = p;
#endif
+ } else if (xp->xp_backslash & XP_BS_COMMA) {
+ if (vim_strchr(files[i], ',') != NULL) {
+ p = vim_strsave_escaped(files[i], ",");
+ if (p != NULL) {
+ xfree(files[i]);
+ files[i] = p;
+ }
+ }
}
#ifdef BACKSLASH_IN_FILENAME
p = vim_strsave_fnameescape(files[i], vse_what);
@@ -890,7 +899,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode)
// Concatenate all matching names. Unless interrupted, this can be slow
// and the result probably won't be used.
- // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne)
if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) {
size_t len = 0;
for (int i = 0; i < xp->xp_numfiles; i++) {
@@ -905,18 +913,19 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode)
}
ss = xmalloc(len);
*ss = NUL;
+ char *ssp = ss;
for (int i = 0; i < xp->xp_numfiles; i++) {
if (i > 0) {
if (xp->xp_prefix == XP_PREFIX_NO) {
- STRCAT(ss, "no");
+ ssp = xstpcpy(ssp, "no");
} else if (xp->xp_prefix == XP_PREFIX_INV) {
- STRCAT(ss, "inv");
+ ssp = xstpcpy(ssp, "inv");
}
}
- STRCAT(ss, xp->xp_files[i]);
+ ssp = xstpcpy(ssp, xp->xp_files[i]);
if (i != xp->xp_numfiles - 1) {
- STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
+ ssp = xstpcpy(ssp, (options & WILD_USE_NL) ? "\n" : " ");
}
}
}
@@ -2440,15 +2449,23 @@ static int expand_files_and_dirs(expand_T *xp, char *pat, char ***matches, int *
pat = xstrdup(pat);
for (int i = 0; pat[i]; i++) {
if (pat[i] == '\\') {
- if (xp->xp_backslash == XP_BS_THREE
+ if (xp->xp_backslash & XP_BS_THREE
&& pat[i + 1] == '\\'
&& pat[i + 2] == '\\'
&& pat[i + 3] == ' ') {
STRMOVE(pat + i, pat + i + 3);
- }
- if (xp->xp_backslash == XP_BS_ONE
- && pat[i + 1] == ' ') {
+ } else if (xp->xp_backslash & XP_BS_ONE
+ && pat[i + 1] == ' ') {
STRMOVE(pat + i, pat + i + 1);
+ } else if ((xp->xp_backslash & XP_BS_COMMA)
+ && pat[i + 1] == '\\'
+ && pat[i + 2] == ',') {
+ STRMOVE(pat + i, pat + i + 2);
+#ifdef BACKSLASH_IN_FILENAME
+ } else if ((xp->xp_backslash & XP_BS_COMMA)
+ && pat[i + 1] == ',') {
+ STRMOVE(pat + i, pat + i + 1);
+#endif
}
}
}