Patch 9.0.0362

2 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 2, 2022, 2:49:03 PM9/2/22
to vim...@googlegroups.com

Patch 9.0.0362
Problem: Expanding ":e %" does not work for remote files.
Solution: If the "%" or "#" file does not exist add the expansion anyway.
Files: src/filepath.c, src/testdir/test_cmdline.vim


*** ../vim-9.0.0361/src/filepath.c 2022-09-01 12:22:19.747659165 +0100
--- src/filepath.c 2022-09-02 19:31:55.695427807 +0100
***************
*** 3088,3104 ****
int ret = FAIL;
char_u *eval_pat = NULL;
char_u *exp_pat = *pat;
! char *ignored_msg;
int usedlen;

! if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<')
{
++emsg_off;
eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
NULL, &ignored_msg, NULL, TRUE);
--emsg_off;
if (eval_pat != NULL)
exp_pat = concat_str(eval_pat, exp_pat + usedlen);
}

if (exp_pat != NULL)
--- 3088,3109 ----
int ret = FAIL;
char_u *eval_pat = NULL;
char_u *exp_pat = *pat;
! char *ignored_msg;
int usedlen;
+ int is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#';
+ int star_follows = FALSE;

! 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,3111 ****
--- 3111,3130 ----

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);
}
*** ../vim-9.0.0361/src/testdir/test_cmdline.vim 2022-09-02 15:15:11.063569185 +0100
--- src/testdir/test_cmdline.vim 2022-09-02 19:40:18.587424616 +0100
***************
*** 1306,1311 ****
--- 1306,1323 ----
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

*** ../vim-9.0.0361/src/version.c 2022-09-02 17:12:03.668881359 +0100
--- src/version.c 2022-09-02 18:56:52.200933475 +0100
***************
*** 709,710 ****
--- 709,712 ----
{ /* Add new patch number below this line */
+ /**/
+ 362,
/**/

--
Your company is doomed if your primary product is overhead transparencies.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages