Skip to content

Commit 87ffb5c

Browse files
committed
patch 8.0.1204: a QuitPre autocommand may get the wrong file name
Problem: A QuitPre autocommand may get the wrong file name. Solution: Pass the buffer being closed to apply_autocmds(). (Rich Howe)
1 parent 6daeef1 commit 87ffb5c

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/ex_docmd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7224,10 +7224,14 @@ ex_quit(exarg_T *eap)
72247224
wp = curwin;
72257225

72267226
#ifdef FEAT_AUTOCMD
7227-
apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf);
7228-
/* Refuse to quit when locked or when the buffer in the last window is
7229-
* being closed (can only happen in autocommands). */
7230-
if (curbuf_locked() || !win_valid(wp)
7227+
/* Refuse to quit when locked. */
7228+
if (curbuf_locked())
7229+
return;
7230+
apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer);
7231+
/* Bail out when autocommands closed the window.
7232+
* Refuse to quit when the buffer in the last window is being closed (can
7233+
* only happen in autocommands). */
7234+
if (!win_valid(wp)
72317235
|| (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0))
72327236
return;
72337237
#endif

src/testdir/test_autocmd.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,17 @@ func Test_BufLeave_Wipe()
779779
" check that bufinfo doesn't contain a pointer to freed memory
780780
call test_garbagecollect_now()
781781
endfunc
782+
783+
func Test_QuitPre()
784+
edit Xfoo
785+
let winid = win_getid(winnr())
786+
split Xbar
787+
au! QuitPre * let g:afile = expand('<afile>')
788+
" Close the other window, <afile> should be correct.
789+
exe win_id2win(winid) . 'q'
790+
call assert_equal('Xfoo', g:afile)
791+
792+
unlet g:afile
793+
bwipe Xfoo
794+
bwipe Xbar
795+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1204,
764766
/**/
765767
1203,
766768
/**/

0 commit comments

Comments
 (0)