Mercurial > vim
changeset 25654:ef38fc02faaa v8.2.3363
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 <Bram@vim.org>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 21 Aug 2021 17:15:03 +0200 |
parents | dc3b761cc059 |
children | cf7cd75766d9 |
files | src/ex_cmds.c src/testdir/test_cmdline.vim src/testdir/test_undo.vim src/testdir/test_vim9_builtin.vim src/testdir/test_vim9_script.vim src/version.c |
diffstat | 6 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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 <afile>', 'E495:') call assert_fails('e <abuf>', 'E496:') call assert_fails('e <amatch>', 'E497:')
--- 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
--- 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)