mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Problem: QuitPre is triggered before :wq writes the file, which is different from other commands. Solution: Trigger QuitPre after writing the file. (closes #8279)
This commit is contained in:
@@ -6089,7 +6089,7 @@ ex_stop(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":exit", ":xit" and ":wq": Write file and quite the current window.
|
* ":exit", ":xit" and ":wq": Write file and quit the current window.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ex_exit(exarg_T *eap)
|
ex_exit(exarg_T *eap)
|
||||||
@@ -6112,17 +6112,17 @@ ex_exit(exarg_T *eap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (before_quit_autocmds(curwin, FALSE, eap->forceit))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if more files or windows we won't exit
|
* we plan to exit if there is only one relevant window
|
||||||
*/
|
*/
|
||||||
if (check_more(FALSE, eap->forceit) == OK && only_one_window())
|
if (check_more(FALSE, eap->forceit) == OK && only_one_window())
|
||||||
exiting = TRUE;
|
exiting = TRUE;
|
||||||
if ( ((eap->cmdidx == CMD_wq
|
|
||||||
|| curbufIsChanged())
|
// Write the buffer for ":wq" or when it was changed.
|
||||||
&& do_write(eap) == FAIL)
|
// Trigger QuitPre and ExitPre.
|
||||||
|
// Check if we can exit now, after autocommands have changed things.
|
||||||
|
if (((eap->cmdidx == CMD_wq || curbufIsChanged()) && do_write(eap) == FAIL)
|
||||||
|
|| before_quit_autocmds(curwin, FALSE, eap->forceit)
|
||||||
|| check_more(TRUE, eap->forceit) == FAIL
|
|| check_more(TRUE, eap->forceit) == FAIL
|
||||||
|| (only_one_window() && check_changed_any(eap->forceit, FALSE)))
|
|| (only_one_window() && check_changed_any(eap->forceit, FALSE)))
|
||||||
{
|
{
|
||||||
|
@@ -915,4 +915,25 @@ func Test_write_binary_file()
|
|||||||
call delete('Xfile3')
|
call delete('Xfile3')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Check that buffer is written before triggering QuitPre
|
||||||
|
func Test_wq_quitpre_autocommand()
|
||||||
|
edit Xsomefile
|
||||||
|
call setline(1, 'hello')
|
||||||
|
split
|
||||||
|
let g:seq = []
|
||||||
|
augroup Testing
|
||||||
|
au QuitPre * call add(g:seq, 'QuitPre - ' .. (&modified ? 'modified' : 'not modified'))
|
||||||
|
au BufWritePost * call add(g:seq, 'written')
|
||||||
|
augroup END
|
||||||
|
wq
|
||||||
|
call assert_equal(['written', 'QuitPre - not modified'], g:seq)
|
||||||
|
|
||||||
|
augroup Testing
|
||||||
|
au!
|
||||||
|
augroup END
|
||||||
|
bwipe!
|
||||||
|
unlet g:seq
|
||||||
|
call delete('Xsomefile')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2900,
|
||||||
/**/
|
/**/
|
||||||
2899,
|
2899,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user