]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2397: Vim9: "%%" not seen as alternate file name for ":bdel" v8.2.2397
authorBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2021 14:15:01 +0000 (15:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2021 14:15:01 +0000 (15:15 +0100)
Problem:    Vim9: "%%" not seen as alternate file name for commands with a
            buffer name argument.
Solution:   Recognize "%%" like "#". (closes #7732)

src/buffer.c
src/testdir/test_vim9_cmd.vim
src/version.c

index c347ef9a64714370b30f0877624622d78542edae..f9bffbf3d8b9a6a2e27727144e5995c96be5df6b 100644 (file)
@@ -2564,12 +2564,15 @@ buflist_findpat(
     char_u     *p;
     int                toggledollar;
 
-    if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#'))
+    // "%" is current file, "%%" or "#" is alternate file
+    if ((pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#'))
+           || (in_vim9script() && pattern_end == pattern + 2
+                                   && pattern[0] == '%' && pattern[1] == '%'))
     {
-       if (*pattern == '%')
-           match = curbuf->b_fnum;
-       else
+       if (*pattern == '#' || pattern_end == pattern + 2)
            match = curwin->w_alt_fnum;
+       else
+           match = curbuf->b_fnum;
 #ifdef FEAT_DIFF
        if (diffmode && !diff_mode_buf(buflist_findnr(match)))
            match = -1;
index 735f48807d81bad3aa3db54fe74adc63e3abbee4..2f8fd71e95393abe4f2d84504b9463a7b461b5fd 100644 (file)
@@ -68,6 +68,17 @@ def Test_expand_alternate_file()
     edit Xfiletwo
     edit %%:r
     assert_equal('Xfileone', bufname())
+
+    assert_false(bufexists('altfoo'))
+    edit altfoo
+    edit bar
+    assert_true(bufexists('altfoo'))
+    assert_true(buflisted('altfoo'))
+    bdel %%
+    assert_true(bufexists('altfoo'))
+    assert_false(buflisted('altfoo'))
+    bwipe! altfoo
+    bwipe! bar
   END
   CheckDefAndScriptSuccess(lines)
 enddef
index af1f7d2959c1dcea50dca2892a569412fa9a4a1e..f63f999e1ee3f7b30b0f352bfe3c2044a3d70e1c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2397,
 /**/
     2396,
 /**/