vim-patch:9.1.2095: :wqall! doesn't quit when using :quit in BufWritePost

Problem:  :wqall! doesn't quit when using :quit in BufWritePost
          (after 8.0.1190).
Solution: Restore old value of "exiting" when calling not_exiting()
          instead of always resetting it to FALSE (zeertzjq).

related: vim/vim#2205
closes:  vim/vim#19212

e803ad1c56
This commit is contained in:
zeertzjq
2026-01-20 06:24:22 +08:00
parent a512d43716
commit 537e8d69f8
3 changed files with 26 additions and 8 deletions

View File

@@ -1878,6 +1878,7 @@ void do_wqall(exarg_T *eap)
{
int error = 0;
int save_forceit = eap->forceit;
bool save_exiting = exiting;
if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) {
if (before_quit_all(eap) == FAIL) {
@@ -1929,7 +1930,7 @@ void do_wqall(exarg_T *eap)
if (!error) {
getout(0); // exit Vim
}
not_exiting();
not_exiting(save_exiting);
}
}

View File

@@ -4698,9 +4698,9 @@ static void ex_highlight(exarg_T *eap)
/// Call this function if we thought we were going to exit, but we won't
/// (because of an error). May need to restore the terminal mode.
void not_exiting(void)
void not_exiting(bool save_exiting)
{
exiting = false;
exiting = save_exiting;
}
bool before_quit_autocmds(win_T *wp, bool quit_all, bool forceit)
@@ -4770,6 +4770,7 @@ static void ex_quit(exarg_T *eap)
return;
}
bool save_exiting = exiting;
// If there is only one relevant window we will exit.
if (check_more(false, eap->forceit) == OK && only_one_window()) {
exiting = true;
@@ -4780,7 +4781,7 @@ static void ex_quit(exarg_T *eap)
| CCGD_EXCMD))
|| check_more(true, eap->forceit) == FAIL
|| (only_one_window() && check_changed_any(eap->forceit, true))) {
not_exiting();
not_exiting(save_exiting);
} else {
// quit last window
// Note: only_one_window() returns true, even so a help window is
@@ -4791,7 +4792,7 @@ static void ex_quit(exarg_T *eap)
if (only_one_window() && (ONE_WINDOW || eap->addr_count == 0)) {
getout(0);
}
not_exiting();
not_exiting(save_exiting);
// close window; may free buffer
win_close(wp, !buf_hide(wp->w_buffer) || eap->forceit, eap->forceit);
}
@@ -4837,11 +4838,12 @@ static void ex_quit_all(exarg_T *eap)
if (before_quit_all(eap) == FAIL) {
return;
}
bool save_exiting = exiting;
exiting = true;
if (eap->forceit || !check_changed_any(false, false)) {
getout(0);
}
not_exiting();
not_exiting(save_exiting);
}
/// ":close": close current window, unless it is the last one
@@ -5104,6 +5106,7 @@ static void ex_exit(exarg_T *eap)
return;
}
bool save_exiting = exiting;
// we plan to exit if there is only one relevant window
if (check_more(false, eap->forceit) == OK && only_one_window()) {
exiting = true;
@@ -5115,13 +5118,13 @@ static void ex_exit(exarg_T *eap)
|| before_quit_autocmds(curwin, false, eap->forceit)
|| check_more(true, eap->forceit) == FAIL
|| (only_one_window() && check_changed_any(eap->forceit, false))) {
not_exiting();
not_exiting(save_exiting);
} else {
if (only_one_window()) {
// quit last window, exit Vim
getout(0);
}
not_exiting();
not_exiting(save_exiting);
// Quit current window, may free the buffer.
win_close(curwin, !buf_hide(curwin->w_buffer), eap->forceit);
}

View File

@@ -93,6 +93,20 @@ func Test_exiting()
call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
endif
call delete('Xtestout')
" Test using :quit in BufWritePost during :wqall
let after =<< trim [CODE]
botright new Xwritebuf
call setline(1, 'SHOULD BE WRITTEN')
autocmd BufWritePost Xwritebuf 1quit
wqall
call setline(1, 'NOT REACHED') | write | qall
[CODE]
if RunVim([], after, '')
call assert_equal(['SHOULD BE WRITTEN'], readfile('Xwritebuf'))
endif
call delete('Xwritebuf')
endfunc
" Test for getting the Vim exit code from v:exiting