aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-09-03 07:51:51 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-09-03 09:01:09 +0800
commitc62e5b50795d38db68f198a3d1230c047fc0ccfa (patch)
treeee597105bada2b66d4d51b6086c70b5e8c39e48a /src/nvim/path.c
parent7243b1cbde8a08deab6bf29b452b3383fa4f6d8d (diff)
downloadrneovim-c62e5b50795d38db68f198a3d1230c047fc0ccfa.tar.gz
rneovim-c62e5b50795d38db68f198a3d1230c047fc0ccfa.tar.bz2
rneovim-c62e5b50795d38db68f198a3d1230c047fc0ccfa.zip
vim-patch:9.0.0362: expanding ":e %" does not work for remote files
Problem: Expanding ":e %" does not work for remote files. Solution: If the "%" or "#" file does not exist add the expansion anyway. https://github.com/vim/vim/commit/f5724376ab7362b5a98eaa8a331d663ef722c2a2
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 607f1fc09a..1e5fa49ad6 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -2106,13 +2106,16 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
char *exp_pat = (char *)(*pat);
char *ignored_msg;
size_t usedlen;
+ const bool is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#';
+ bool star_follows = false;
- if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<') {
+ if (is_cur_alt_file || *exp_pat == '<') {
emsg_off++;
eval_pat = eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, NULL,
true);
emsg_off--;
if (eval_pat != NULL) {
+ star_follows = strcmp(exp_pat + usedlen, "*") == 0;
exp_pat = concat_str((char *)eval_pat, exp_pat + usedlen);
}
}
@@ -2122,6 +2125,16 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
}
if (eval_pat != NULL) {
+ if (*num_file == 0 && is_cur_alt_file && star_follows) {
+ // Expanding "%" or "#" and the file does not exist: Add the
+ // pattern anyway (without the star) so that this works for remote
+ // files and non-file buffer names.
+ *file = xmalloc(sizeof(char *));
+ **file = (char *)eval_pat;
+ eval_pat = NULL;
+ *num_file = 1;
+ ret = OK;
+ }
xfree(exp_pat);
xfree(eval_pat);
}