@@ -7187,8 +7187,35 @@ not_exiting(void)
71877187 settmode (TMODE_RAW );
71887188}
71897189
7190+ static int
7191+ before_quit_autocmds (win_T * wp , int quit_all , int forceit )
7192+ {
7193+ apply_autocmds (EVENT_QUITPRE , NULL , NULL , FALSE, wp -> w_buffer );
7194+
7195+ /* Bail out when autocommands closed the window.
7196+ * Refuse to quit when the buffer in the last window is being closed (can
7197+ * only happen in autocommands). */
7198+ if (!win_valid (wp )
7199+ || curbuf_locked ()
7200+ || (wp -> w_buffer -> b_nwindows == 1 && wp -> w_buffer -> b_locked > 0 ))
7201+ return TRUE;
7202+
7203+ if (quit_all || (check_more (FALSE, forceit ) == OK && only_one_window ()))
7204+ {
7205+ apply_autocmds (EVENT_EXITPRE , NULL , NULL , FALSE, curbuf );
7206+ /* Refuse to quit when locked or when the buffer in the last window is
7207+ * being closed (can only happen in autocommands). */
7208+ if (curbuf_locked ()
7209+ || (curbuf -> b_nwindows == 1 && curbuf -> b_locked > 0 ))
7210+ return TRUE;
7211+ }
7212+
7213+ return FALSE;
7214+ }
7215+
71907216/*
71917217 * ":quit": quit current window, quit Vim if the last window is closed.
7218+ * ":{nr}quit": quit window {nr}
71927219 */
71937220 static void
71947221ex_quit (exarg_T * eap )
@@ -7222,12 +7249,9 @@ ex_quit(exarg_T *eap)
72227249 /* Refuse to quit when locked. */
72237250 if (curbuf_locked ())
72247251 return ;
7225- apply_autocmds (EVENT_QUITPRE , NULL , NULL , FALSE, wp -> w_buffer );
7226- /* Bail out when autocommands closed the window.
7227- * Refuse to quit when the buffer in the last window is being closed (can
7228- * only happen in autocommands). */
7229- if (!win_valid (wp )
7230- || (wp -> w_buffer -> b_nwindows == 1 && wp -> w_buffer -> b_locked > 0 ))
7252+
7253+ /* Trigger QuitPre and maybe ExitPre */
7254+ if (before_quit_autocmds (wp , FALSE, eap -> forceit ))
72317255 return ;
72327256
72337257#ifdef FEAT_NETBEANS_INTG
@@ -7301,10 +7325,8 @@ ex_quit_all(exarg_T *eap)
73017325 text_locked_msg ();
73027326 return ;
73037327 }
7304- apply_autocmds (EVENT_QUITPRE , NULL , NULL , FALSE, curbuf );
7305- /* Refuse to quit when locked or when the buffer in the last window is
7306- * being closed (can only happen in autocommands). */
7307- if (curbuf_locked () || (curbuf -> b_nwindows == 1 && curbuf -> b_locked > 0 ))
7328+
7329+ if (before_quit_autocmds (curwin , TRUE, eap -> forceit ))
73087330 return ;
73097331
73107332 exiting = TRUE;
@@ -7743,7 +7765,7 @@ ex_stop(exarg_T *eap)
77437765}
77447766
77457767/*
7746- * ":exit", ":xit" and ":wq": Write file and exit Vim .
7768+ * ":exit", ":xit" and ":wq": Write file and quite the current window .
77477769 */
77487770 static void
77497771ex_exit (exarg_T * eap )
@@ -7761,10 +7783,8 @@ ex_exit(exarg_T *eap)
77617783 text_locked_msg ();
77627784 return ;
77637785 }
7764- apply_autocmds (EVENT_QUITPRE , NULL , NULL , FALSE, curbuf );
7765- /* Refuse to quit when locked or when the buffer in the last window is
7766- * being closed (can only happen in autocommands). */
7767- if (curbuf_locked () || (curbuf -> b_nwindows == 1 && curbuf -> b_locked > 0 ))
7786+
7787+ if (before_quit_autocmds (curwin , FALSE, eap -> forceit ))
77687788 return ;
77697789
77707790 /*
0 commit comments