Skip to content

Commit dfbc5fd

Browse files
committed
patch 8.2.2397: Vim9: "%%" not seen as alternate file name for ":bdel"
Problem: Vim9: "%%" not seen as alternate file name for commands with a buffer name argument. Solution: Recognize "%%" like "#". (closes #7732)
1 parent 7cebe8b commit dfbc5fd

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/buffer.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,12 +2564,15 @@ buflist_findpat(
25642564
char_u *p;
25652565
int toggledollar;
25662566

2567-
if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#'))
2567+
// "%" is current file, "%%" or "#" is alternate file
2568+
if ((pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#'))
2569+
|| (in_vim9script() && pattern_end == pattern + 2
2570+
&& pattern[0] == '%' && pattern[1] == '%'))
25682571
{
2569-
if (*pattern == '%')
2570-
match = curbuf->b_fnum;
2571-
else
2572+
if (*pattern == '#' || pattern_end == pattern + 2)
25722573
match = curwin->w_alt_fnum;
2574+
else
2575+
match = curbuf->b_fnum;
25732576
#ifdef FEAT_DIFF
25742577
if (diffmode && !diff_mode_buf(buflist_findnr(match)))
25752578
match = -1;

src/testdir/test_vim9_cmd.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def Test_expand_alternate_file()
6868
edit Xfiletwo
6969
edit %%:r
7070
assert_equal('Xfileone', bufname())
71+
72+
assert_false(bufexists('altfoo'))
73+
edit altfoo
74+
edit bar
75+
assert_true(bufexists('altfoo'))
76+
assert_true(buflisted('altfoo'))
77+
bdel %%
78+
assert_true(bufexists('altfoo'))
79+
assert_false(buflisted('altfoo'))
80+
bwipe! altfoo
81+
bwipe! bar
7182
END
7283
CheckDefAndScriptSuccess(lines)
7384
enddef

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2397,
753755
/**/
754756
2396,
755757
/**/

0 commit comments

Comments
 (0)