Test for BufWritePre autocommand that deletes or unloads the buffer.
+Test for BufUnload autocommand that unloads all other buffers.
STARTTEST
:so small.vim
:bwipe test.out " remove test.out from the buffer list
:w " write it, will delete the buffer and give an error msg
:w >>test.out " Append contents of this file
+:au! BufWritePre
+:func CloseAll()
+ let i = 0
+ while i <= bufnr('$')
+ if i != bufnr('%') && bufloaded(i)
+ exe i . "bunload"
+ endif
+ let i += 1
+ endwhile
+endfunc
+:func WriteToOut()
+ edit! test.out
+ $put ='VimLeave done'
+ write
+endfunc
+:set viminfo='100,nviminfo
+:au BufUnload * call CloseAll()
+:au VimLeave * call WriteToOut()
+:e small.vim
+:sp mbyte.vim
+:q
:qa!
ENDTEST
if (only_one_window() && win_valid(win) && win->w_buffer == NULL
&& (last_window() || curtab != prev_curtab
|| close_last_window_tabpage(win, free_buf, prev_curtab)))
- /* Autocommands have close all windows, quit now. */
+ {
+ /* Autocommands have close all windows, quit now. Restore
+ * curwin->w_buffer, otherwise writing viminfo may fail. */
+ if (curwin->w_buffer == NULL)
+ curwin->w_buffer = curbuf;
getout(0);
+ }
/* Autocommands may have closed the window already, or closed the only
* other window or moved to another tab page. */