Patch 8.2.2900
Problem: QuitPre is triggered before :wq writes the file, which is
different from other commands.
Solution: Trigger QuitPre after writing the file. (closes #8279)
Files: src/ex_docmd.c, src/testdir/test_writefile.vim
*** ../vim-8.2.2899/src/ex_docmd.c 2021-05-29 12:21:54.948859803 +0200
--- src/ex_docmd.c 2021-05-29 13:20:30.386336194 +0200
***************
*** 6089,6095 ****
}
/*
! * ":exit", ":xit" and ":wq": Write file and quite the current window.
*/
static void
ex_exit(exarg_T *eap)
--- 6089,6095 ----
}
/*
! * ":exit", ":xit" and ":wq": Write file and quit the current window.
*/
static void
ex_exit(exarg_T *eap)
***************
*** 6112,6128 ****
return;
}
- if (before_quit_autocmds(curwin, FALSE, eap->forceit))
- return;
-
/*
! * if more files or windows we won't exit
*/
if (check_more(FALSE, eap->forceit) == OK && only_one_window())
exiting = TRUE;
! if ( ((eap->cmdidx == CMD_wq
! || curbufIsChanged())
! && do_write(eap) == FAIL)
|| check_more(TRUE, eap->forceit) == FAIL
|| (only_one_window() && check_changed_any(eap->forceit, FALSE)))
{
--- 6112,6128 ----
return;
}
/*
! * we plan to exit if there is only one relevant window
*/
if (check_more(FALSE, eap->forceit) == OK && only_one_window())
exiting = TRUE;
!
! // Write the buffer for ":wq" or when it was changed.
! // 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
|| (only_one_window() && check_changed_any(eap->forceit, FALSE)))
{
*** ../vim-8.2.2899/src/testdir/test_writefile.vim 2021-05-19 17:15:00.825866111 +0200
--- src/testdir/test_writefile.vim 2021-05-29 14:27:18.708762711 +0200
***************
*** 915,918 ****
--- 915,939 ----
call delete('Xfile3')
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-8.2.2899/src/version.c 2021-05-29 12:42:43.983850833 +0200
--- src/version.c 2021-05-29 13:21:50.718137723 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2900,
/**/
--
It's not hard to meet expenses, they're everywhere.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///