vim-patch:9.0.1538: :wqall does not trigger ExitPre (#23574)

Problem:    :wqall does not trigger ExitPre. (Bart Libert)
Solution:   Move preparations for :qall to a common function. (closes vim/vim#12374)

411da64e77

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-05-11 08:09:13 +08:00
committed by GitHub
parent ac1aee99bc
commit 9d306ac6b7
3 changed files with 30 additions and 5 deletions

View File

@@ -1926,6 +1926,9 @@ void do_wqall(exarg_T *eap)
int save_forceit = eap->forceit; int save_forceit = eap->forceit;
if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) { if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) {
if (before_quit_all(eap) == FAIL) {
return;
}
exiting = true; exiting = true;
} }

View File

@@ -4589,8 +4589,9 @@ static void ex_cquit(exarg_T *eap)
getout(eap->addr_count > 0 ? (int)eap->line2 : EXIT_FAILURE); getout(eap->addr_count > 0 ? (int)eap->line2 : EXIT_FAILURE);
} }
/// ":qall": try to quit all windows /// Do preparations for "qall" and "wqall".
static void ex_quit_all(exarg_T *eap) /// Returns FAIL when quitting should be aborted.
int before_quit_all(exarg_T *eap)
{ {
if (cmdwin_type != 0) { if (cmdwin_type != 0) {
if (eap->forceit) { if (eap->forceit) {
@@ -4598,19 +4599,28 @@ static void ex_quit_all(exarg_T *eap)
} else { } else {
cmdwin_result = K_XF2; cmdwin_result = K_XF2;
} }
return; return FAIL;
} }
// Don't quit while editing the command line. // Don't quit while editing the command line.
if (text_locked()) { if (text_locked()) {
text_locked_msg(); text_locked_msg();
return; return FAIL;
} }
if (before_quit_autocmds(curwin, true, eap->forceit)) { if (before_quit_autocmds(curwin, true, eap->forceit)) {
return; return FAIL;
} }
return OK;
}
/// ":qall": try to quit all windows
static void ex_quit_all(exarg_T *eap)
{
if (before_quit_all(eap) == FAIL) {
return;
}
exiting = true; exiting = true;
if (eap->forceit || !check_changed_any(false, false)) { if (eap->forceit || !check_changed_any(false, false)) {
getout(0); getout(0);

View File

@@ -81,6 +81,18 @@ func Test_exiting()
\ readfile('Xtestout')) \ readfile('Xtestout'))
endif endif
call delete('Xtestout') call delete('Xtestout')
" ExitPre autocommand also executed on :wqall
let after =<< trim [CODE]
au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")
au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
wqall
[CODE]
if RunVim([], after, '')
call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
endif
call delete('Xtestout')
endfunc endfunc
" Test for getting the Vim exit code from v:exiting " Test for getting the Vim exit code from v:exiting