// If the buffer was in curwin and the window has changed, go back to that
// window, if it still exists. This avoids that ":edit x" triggering a
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
- if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
+ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
{
block_autocmds();
goto_tabpage_win(the_curtab, the_curwin);
/*
* Remove the buffer from the list.
+ * Do not wipe out the buffer if it is used in a window.
*/
- if (wipe_buf)
+ if (wipe_buf && buf->b_nwindows <= 0)
{
tabpage_T *tp;
win_T *wp;
- // Do not wipe out the buffer if it is used in a window.
- if (buf->b_nwindows > 0)
- return FALSE;
-
FOR_ALL_TAB_WINDOWS(tp, wp)
mark_forget_file(wp, buf->b_fnum);
close!
endfunc
-" Test for BufWipeouti autocmd changing the current buffer when reading a file
+" Test for BufWipeout autocmd changing the current buffer when reading a file
" in an empty buffer with 'f' flag in 'cpo'
func Test_BufDelete_changebuf()
new
%bwipe!
endfunc
+func Test_autocmd_prevent_buf_wipe()
+ " Xa must be the first buffer so that win_close_othertab() puts it in
+ " another window, which causes wiping the buffer to fail.
+ %bwipe!
+
+ file Xa
+ call setline(1, 'foo')
+ setlocal bufhidden=wipe
+ tabnew Xb
+ setlocal bufhidden=wipe
+ autocmd BufUnload Xa ++once ++nested tabonly
+ autocmd BufWinLeave Xb ++once tabnext
+ tabfirst
+
+ edit! Xc
+ call assert_equal('Xc', bufname('%'))
+ tabnext
+ call assert_equal('Xa', bufname('%'))
+ call assert_equal("\n\"Xa\" --No lines in buffer--", execute('file'))
+
+ %bwipe!
+endfunc
+
func Test_v_event_readonly()
autocmd CompleteChanged * let v:event.width = 0
call assert_fails("normal! i\<C-X>\<C-V>", 'E46:')