0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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)
This commit is contained in:
Bram Moolenaar 2021-08-21 17:13:14 +02:00
parent 489d60996d
commit b8bd2e6eba
6 changed files with 12 additions and 4 deletions

View File

@ -2648,6 +2648,8 @@ do_ecmd(
*/ */
if (other_file) if (other_file)
{ {
int prev_alt_fnum = curwin->w_alt_fnum;
if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF)))
{ {
if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
@ -2691,6 +2693,10 @@ do_ecmd(
} }
if (buf == NULL) if (buf == NULL)
goto theend; 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 if (buf->b_ml.ml_mfp == NULL) // no memfile yet
{ {
oldbuf = FALSE; oldbuf = FALSE;

View File

@ -1365,7 +1365,7 @@ endfunc
" Test for expanding special keywords in cmdline " Test for expanding special keywords in cmdline
func Test_cmdline_expand_special() func Test_cmdline_expand_special()
%bwipe! %bwipe!
call assert_fails('e #', 'E499:') call assert_fails('e #', 'E194:')
call assert_fails('e <afile>', 'E495:') call assert_fails('e <afile>', 'E495:')
call assert_fails('e <abuf>', 'E496:') call assert_fails('e <abuf>', 'E496:')
call assert_fails('e <amatch>', 'E497:') call assert_fails('e <amatch>', 'E497:')

View File

@ -582,7 +582,7 @@ func Test_undofile_2()
" add 10 lines, delete 6 lines, undo 3 " add 10 lines, delete 6 lines, undo 3
set undofile 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']) \ 'seven', 'eight', 'nine', 'ten'])
set undolevels=100 set undolevels=100
normal 3Gdd normal 3Gdd

View File

@ -1268,7 +1268,7 @@ enddef
def Test_getbufline() def Test_getbufline()
e SomeFile e SomeFile
var buf = bufnr() var buf = bufnr()
e # sp Otherfile
var lines = ['aaa', 'bbb', 'ccc'] var lines = ['aaa', 'bbb', 'ccc']
setbufline(buf, 1, lines) setbufline(buf, 1, lines)
getbufline('#', 1, '$')->assert_equal(lines) getbufline('#', 1, '$')->assert_equal(lines)

View File

@ -3495,7 +3495,7 @@ def Test_vim9_comment_gui()
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'gui -f#comment' 'gui -f#comment'
], 'E499:') ], 'E194:')
enddef enddef
def Test_vim9_comment_not_compiled() def Test_vim9_comment_not_compiled()

View File

@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3363,
/**/ /**/
3362, 3362,
/**/ /**/