]> granicus.if.org Git - vim/commitdiff
patch 8.0.1204: a QuitPre autocommand may get the wrong file name v8.0.1204
authorBram Moolenaar <Bram@vim.org>
Thu, 19 Oct 2017 10:37:42 +0000 (12:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 19 Oct 2017 10:37:42 +0000 (12:37 +0200)
Problem:    A QuitPre autocommand may get the wrong file name.
Solution:   Pass the buffer being closed to apply_autocmds(). (Rich Howe)

src/ex_docmd.c
src/testdir/test_autocmd.vim
src/version.c

index 7365d1bd3a327c0b968f35ec4c54c8bfe7d4887a..905cdd4b046d670d1fba37f583eaeb6d034dbb87 100644 (file)
@@ -7224,10 +7224,14 @@ ex_quit(exarg_T *eap)
        wp = curwin;
 
 #ifdef FEAT_AUTOCMD
-    apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf);
-    /* Refuse to quit when locked or when the buffer in the last window is
-     * being closed (can only happen in autocommands). */
-    if (curbuf_locked() || !win_valid(wp)
+    /* Refuse to quit when locked. */
+    if (curbuf_locked())
+       return;
+    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))
        return;
 #endif
index 593d1cc4098864cb5eb7064bf3d5f2605a47b59b..f5a228995a76b7e2676fe5fca054af0b75904788 100644 (file)
@@ -779,3 +779,17 @@ func Test_BufLeave_Wipe()
   " check that bufinfo doesn't contain a pointer to freed memory
   call test_garbagecollect_now()
 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
index 32140089f6efe260fa20189113dd033926822092..da06043d46b03be4d4c51ed40e27c6120adf144b 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1204,
 /**/
     1203,
 /**/