# HG changeset patch # User Bram Moolenaar # Date 1629558903 -7200 # Node ID ef38fc02faaa337311193c7aa37403766459bb77 # Parent dc3b761cc059037be5bef20e11af7589bb149da2 patch 8.2.3363: when :edit reuses the current buffer the alternate file is set Commit: https://github.com/vim/vim/commit/b8bd2e6ebab03baf2672067067a599df69a278c0 Author: Bram Moolenaar Date: Sat Aug 21 17:13:14 2021 +0200 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) diff --git a/src/ex_cmds.c b/src/ex_cmds.c --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2648,6 +2648,8 @@ do_ecmd( */ if (other_file) { + int prev_alt_fnum = curwin->w_alt_fnum; + if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) { if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) @@ -2691,6 +2693,10 @@ do_ecmd( } if (buf == NULL) goto theend; + if (curwin->w_alt_fnum == buf->b_fnum && prev_alt_fnum != 0) + // reusing the buffer, keep the old alternate file + curwin->w_alt_fnum = prev_alt_fnum; + if (buf->b_ml.ml_mfp == NULL) // no memfile yet { oldbuf = FALSE; diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -1365,7 +1365,7 @@ endfunc " Test for expanding special keywords in cmdline func Test_cmdline_expand_special() %bwipe! - call assert_fails('e #', 'E499:') + call assert_fails('e #', 'E194:') call assert_fails('e ', 'E495:') call assert_fails('e ', 'E496:') call assert_fails('e ', 'E497:') diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim --- a/src/testdir/test_undo.vim +++ b/src/testdir/test_undo.vim @@ -582,7 +582,7 @@ func Test_undofile_2() " add 10 lines, delete 6 lines, undo 3 set undofile - call setbufline(0, 1, ['one', 'two', 'three', 'four', 'five', 'six', + call setbufline('%', 1, ['one', 'two', 'three', 'four', 'five', 'six', \ 'seven', 'eight', 'nine', 'ten']) set undolevels=100 normal 3Gdd diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -1268,7 +1268,7 @@ enddef def Test_getbufline() e SomeFile var buf = bufnr() - e # + sp Otherfile var lines = ['aaa', 'bbb', 'ccc'] setbufline(buf, 1, lines) getbufline('#', 1, '$')->assert_equal(lines) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -3495,7 +3495,7 @@ def Test_vim9_comment_gui() CheckScriptFailure([ 'vim9script', 'gui -f#comment' - ], 'E499:') + ], 'E194:') enddef def Test_vim9_comment_not_compiled() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3363, +/**/ 3362, /**/ 3361,