File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -707,7 +707,7 @@ close_buffer(
707707 // If the buffer was in curwin and the window has changed, go back to that
708708 // window, if it still exists. This avoids that ":edit x" triggering a
709709 // "tabnext" BufUnload autocmd leaves a window behind without a buffer.
710- if (is_curwin && curwin != the_curwin && win_valid_any_tab (the_curwin ))
710+ if (is_curwin && curwin != the_curwin && win_valid_any_tab (the_curwin ))
711711 {
712712 block_autocmds ();
713713 goto_tabpage_win (the_curtab , the_curwin );
@@ -782,16 +782,13 @@ close_buffer(
782782
783783 /*
784784 * Remove the buffer from the list.
785+ * Do not wipe out the buffer if it is used in a window.
785786 */
786- if (wipe_buf )
787+ if (wipe_buf && buf -> b_nwindows <= 0 )
787788 {
788789 tabpage_T * tp ;
789790 win_T * wp ;
790791
791- // Do not wipe out the buffer if it is used in a window.
792- if (buf -> b_nwindows > 0 )
793- return FALSE;
794-
795792 FOR_ALL_TAB_WINDOWS (tp , wp )
796793 mark_forget_file (wp , buf -> b_fnum );
797794
Original file line number Diff line number Diff line change @@ -3696,7 +3696,7 @@ func Test_BufReadPre_changebuf()
36963696 close !
36973697endfunc
36983698
3699- " Test for BufWipeouti autocmd changing the current buffer when reading a file
3699+ " Test for BufWipeout autocmd changing the current buffer when reading a file
37003700" in an empty buffer with 'f' flag in 'cpo'
37013701func Test_BufDelete_changebuf ()
37023702 new
@@ -4016,6 +4016,29 @@ func Test_bufwipeout_changes_window()
40164016 % bwipe!
40174017endfunc
40184018
4019+ func Test_autocmd_prevent_buf_wipe ()
4020+ " Xa must be the first buffer so that win_close_othertab() puts it in
4021+ " another window, which causes wiping the buffer to fail.
4022+ % bwipe!
4023+
4024+ file Xa
4025+ call setline (1 , ' foo' )
4026+ setlocal bufhidden = wipe
4027+ tabnew Xb
4028+ setlocal bufhidden = wipe
4029+ autocmd BufUnload Xa ++once ++ nested tabonly
4030+ autocmd BufWinLeave Xb ++once tabnext
4031+ tabfirst
4032+
4033+ edit ! Xc
4034+ call assert_equal (' Xc' , bufname (' %' ))
4035+ tabnext
4036+ call assert_equal (' Xa' , bufname (' %' ))
4037+ call assert_equal (" \n \" Xa\" --No lines in buffer--" , execute (' file' ))
4038+
4039+ % bwipe!
4040+ endfunc
4041+
40194042func Test_v_event_readonly ()
40204043 autocmd CompleteChanged * let v: event .width = 0
40214044 call assert_fails (" normal! i\<C-X>\<C-V> " , ' E46:' )
Original file line number Diff line number Diff line change @@ -734,6 +734,8 @@ static char *(features[]) =
734734
735735static int included_patches [] =
736736{ /* Add new patch number below this line */
737+ /**/
738+ 2055 ,
737739/**/
738740 2054 ,
739741/**/
You can’t perform that action at this time.
0 commit comments