0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2017-10-19 12:37:42 +02:00
parent 6daeef1933
commit 87ffb5c1a3
3 changed files with 24 additions and 4 deletions

View File

@@ -7224,10 +7224,14 @@ ex_quit(exarg_T *eap)
wp = curwin; wp = curwin;
#ifdef FEAT_AUTOCMD #ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf); /* Refuse to quit when locked. */
/* Refuse to quit when locked or when the buffer in the last window is if (curbuf_locked())
* being closed (can only happen in autocommands). */ return;
if (curbuf_locked() || !win_valid(wp) apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer);
/* Bail out when autocommands closed the window.
* Refuse to quit when the buffer in the last window is being closed (can
* only happen in autocommands). */
if (!win_valid(wp)
|| (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0))
return; return;
#endif #endif

View File

@@ -779,3 +779,17 @@ func Test_BufLeave_Wipe()
" check that bufinfo doesn't contain a pointer to freed memory " check that bufinfo doesn't contain a pointer to freed memory
call test_garbagecollect_now() call test_garbagecollect_now()
endfunc endfunc
func Test_QuitPre()
edit Xfoo
let winid = win_getid(winnr())
split Xbar
au! QuitPre * let g:afile = expand('<afile>')
" Close the other window, <afile> should be correct.
exe win_id2win(winid) . 'q'
call assert_equal('Xfoo', g:afile)
unlet g:afile
bwipe Xfoo
bwipe Xbar
endfunc

View File

@@ -761,6 +761,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 */
/**/
1204,
/**/ /**/
1203, 1203,
/**/ /**/