Skip to content

Commit b8bd2e6

Browse files
committed
patch 8.2.3363: when :edit reuses the current buffer the alternate file is set
Problem: When :edit reuses the current buffer the alternate file is set to the same buffer. Solution: Only set the alternate file when not reusing the buffer. (closes #8783)
1 parent 489d609 commit b8bd2e6

File tree

6 files changed

+12
-4
lines changed

6 files changed

+12
-4
lines changed

src/ex_cmds.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,8 @@ do_ecmd(
26482648
*/
26492649
if (other_file)
26502650
{
2651+
int prev_alt_fnum = curwin->w_alt_fnum;
2652+
26512653
if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF)))
26522654
{
26532655
if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
@@ -2691,6 +2693,10 @@ do_ecmd(
26912693
}
26922694
if (buf == NULL)
26932695
goto theend;
2696+
if (curwin->w_alt_fnum == buf->b_fnum && prev_alt_fnum != 0)
2697+
// reusing the buffer, keep the old alternate file
2698+
curwin->w_alt_fnum = prev_alt_fnum;
2699+
26942700
if (buf->b_ml.ml_mfp == NULL) // no memfile yet
26952701
{
26962702
oldbuf = FALSE;

src/testdir/test_cmdline.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ endfunc
13651365
" Test for expanding special keywords in cmdline
13661366
func Test_cmdline_expand_special()
13671367
%bwipe!
1368-
call assert_fails('e #', 'E499:')
1368+
call assert_fails('e #', 'E194:')
13691369
call assert_fails('e <afile>', 'E495:')
13701370
call assert_fails('e <abuf>', 'E496:')
13711371
call assert_fails('e <amatch>', 'E497:')

src/testdir/test_undo.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func Test_undofile_2()
582582

583583
" add 10 lines, delete 6 lines, undo 3
584584
set undofile
585-
call setbufline(0, 1, ['one', 'two', 'three', 'four', 'five', 'six',
585+
call setbufline('%', 1, ['one', 'two', 'three', 'four', 'five', 'six',
586586
\ 'seven', 'eight', 'nine', 'ten'])
587587
set undolevels=100
588588
normal 3Gdd

src/testdir/test_vim9_builtin.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ enddef
12681268
def Test_getbufline()
12691269
e SomeFile
12701270
var buf = bufnr()
1271-
e #
1271+
sp Otherfile
12721272
var lines = ['aaa', 'bbb', 'ccc']
12731273
setbufline(buf, 1, lines)
12741274
getbufline('#', 1, '$')->assert_equal(lines)

src/testdir/test_vim9_script.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,7 @@ def Test_vim9_comment_gui()
34953495
CheckScriptFailure([
34963496
'vim9script',
34973497
'gui -f#comment'
3498-
], 'E499:')
3498+
], 'E194:')
34993499
enddef
35003500

35013501
def Test_vim9_comment_not_compiled()

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3363,
758760
/**/
759761
3362,
760762
/**/

0 commit comments

Comments
 (0)