]> granicus.if.org Git - vim/commitdiff
patch 8.2.3363: when :edit reuses the current buffer the alternate file is set v8.2.3363
authorBram Moolenaar <Bram@vim.org>
Sat, 21 Aug 2021 15:13:14 +0000 (17:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 21 Aug 2021 15:13:14 +0000 (17:13 +0200)
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)

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

index d30db91952ee7ab478f3e6af5bb52a048de8a726..021296d38c248a39cc0e2ac6b9bff710f5ff6e39 100644 (file)
@@ -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;
index d04bb4c8cb186b8f99e09b1494367fda76ea9163..bd2ca03b60ad8601b3c31fc66b8dd5f556117a87 100644 (file)
@@ -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:')
index 2621412fa0181464e8799ff5a8d95e5dcc83496f..bfcc538d9350acd15f330e29938449fd69e2c563 100644 (file)
@@ -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
index 00d021fe194ac07e9198537723dbbbded79b0967..434f477488704c53a5e896986d0c26b96ef6b469 100644 (file)
@@ -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)
index ffea2acb27af1556ddee59f449f166204ac98980..fd93c3a8b84bdbaf37a52d32b69db6077f48d764 100644 (file)
@@ -3495,7 +3495,7 @@ def Test_vim9_comment_gui()
   CheckScriptFailure([
       'vim9script',
       'gui -f#comment'
-      ], 'E499:')
+      ], 'E194:')
 enddef
 
 def Test_vim9_comment_not_compiled()
index dfe949d9d0428fc5369abad29c2b2d0a29cb8a54..25e0d82ffe814088d92d6620cba3bc03f16d8eda 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3363,
 /**/
     3362,
 /**/