wp = curwin;
#ifdef FEAT_AUTOCMD
- apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf);
- /* Refuse to quit when locked or when the buffer in the last window is
- * being closed (can only happen in autocommands). */
- if (curbuf_locked() || !win_valid(wp)
+ /* Refuse to quit when locked. */
+ if (curbuf_locked())
+ return;
+ apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer);
+ /* Bail out when autocommands closed the window.
+ * Refuse to quit when the buffer in the last window is being closed (can
+ * only happen in autocommands). */
+ if (!win_valid(wp)
|| (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0))
return;
#endif
" check that bufinfo doesn't contain a pointer to freed memory
call test_garbagecollect_now()
endfunc
+
+func Test_QuitPre()
+ edit Xfoo
+ let winid = win_getid(winnr())
+ split Xbar
+ au! QuitPre * let g:afile = expand('<afile>')
+ " Close the other window, <afile> should be correct.
+ exe win_id2win(winid) . 'q'
+ call assert_equal('Xfoo', g:afile)
+
+ unlet g:afile
+ bwipe Xfoo
+ bwipe Xbar
+endfunc