summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-02 19:45:15 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-02 19:45:15 +0100
commitf5724376ab7362b5a98eaa8a331d663ef722c2a2 (patch)
tree8f94b50adb9196c5d9b9f9df0c4ef18700367df2
parent956be4678fba2051a8d24c15cc5dc67fb89c515f (diff)
patch 9.0.0362: expanding ":e %" does not work for remote filesv9.0.0362
Problem: Expanding ":e %" does not work for remote files. Solution: If the "%" or "#" file does not exist add the expansion anyway.
-rw-r--r--src/filepath.c23
-rw-r--r--src/testdir/test_cmdline.vim12
-rw-r--r--src/version.c2
3 files changed, 35 insertions, 2 deletions
diff --git a/src/filepath.c b/src/filepath.c
index c61d711904..b824529fbc 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -3088,17 +3088,22 @@ expand_wildcards_eval(
int ret = FAIL;
char_u *eval_pat = NULL;
char_u *exp_pat = *pat;
- char *ignored_msg;
+ char *ignored_msg;
int usedlen;
+ int is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#';
+ int star_follows = FALSE;
- if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<')
+ if (is_cur_alt_file || *exp_pat == '<')
{
++emsg_off;
eval_pat = eval_vars(exp_pat, 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(eval_pat, exp_pat + usedlen);
+ }
}
if (exp_pat != NULL)
@@ -3106,6 +3111,20 @@ expand_wildcards_eval(
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 = ALLOC_ONE(char_u *);
+ if (*file != NULL)
+ {
+ **file = eval_pat;
+ eval_pat = NULL;
+ *num_file = 1;
+ ret = OK;
+ }
+ }
vim_free(exp_pat);
vim_free(eval_pat);
}
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 335e756d6f..80e82eaeb0 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -1306,6 +1306,18 @@ func Test_cmdline_write_alternatefile()
bw!
endfunc
+func Test_cmdline_expand_cur_alt_file()
+ enew
+ file http://some.com/file.txt
+ call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"e http://some.com/file.txt', @:)
+ edit another
+ call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"e http://some.com/file.txt', @:)
+ bwipe
+ bwipe http://some.com/file.txt
+endfunc
+
" using a leading backslash here
set cpo+=C
diff --git a/src/version.c b/src/version.c
index c6d3869db8..7607e57afc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -708,6 +708,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 362,
+/**/
361,
/**/
360,