0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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.
This commit is contained in:
Bram Moolenaar
2022-09-02 19:45:15 +01:00
parent 956be4678f
commit f5724376ab
3 changed files with 35 additions and 2 deletions

View File

@@ -3090,22 +3090,41 @@ expand_wildcards_eval(
char_u *exp_pat = *pat;
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)
ret = expand_wildcards(1, &exp_pat, num_file, file, 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 = 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);
}

View File

@@ -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

View File

@@ -707,6 +707,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
362,
/**/
361,
/**/