]> granicus.if.org Git - vim/commitdiff
patch 9.0.0362: expanding ":e %" does not work for remote files v9.0.0362
authorBram Moolenaar <Bram@vim.org>
Fri, 2 Sep 2022 18:45:15 +0000 (19:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 2 Sep 2022 18:45:15 +0000 (19:45 +0100)
Problem:    Expanding ":e %" does not work for remote files.
Solution:   If the "%" or "#" file does not exist add the expansion anyway.

src/filepath.c
src/testdir/test_cmdline.vim
src/version.c

index c61d7119040087cdbe0fc906cb85da522fb1a34e..b824529fbce652d3efcbbb9e04bec91e2227b1f0 100644 (file)
@@ -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);
     }
index 335e756d6fa4985746e59c8d67baa13abed4919e..80e82eaeb03fd6f60fb1e84d59ce1eda6b8171f3 100644 (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
 
index c6d3869db81f3b1f3b80074f8499213b77c52251..7607e57afcbe969d17b50ac1959bf5db0a3ac36d 100644 (file)
@@ -707,6 +707,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    362,
 /**/
     361,
 /**/