]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4791: events triggered in different order when reusing buffer v8.2.4791
authorCharlie Groves <charlie.groves@gmail.com>
Tue, 19 Apr 2022 15:24:12 +0000 (16:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Apr 2022 15:24:12 +0000 (16:24 +0100)
Problem:    Autocmd events triggered in different order when reusing an empty
            buffer.
Solution:   Call buff_freeall() earlier. (Charlie Groves, closes #10198)

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

index 50aa9e8cc1b03e4cf5c6a6a74311601478dfd512..461950307c4d0ff9b449bc4d5724a4c48f252bab 100644 (file)
@@ -2068,10 +2068,9 @@ buflist_new(
        buf = curbuf;
        // It's like this buffer is deleted.  Watch out for autocommands that
        // change curbuf!  If that happens, allocate a new buffer anyway.
-       if (curbuf->b_p_bl)
-           apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
-       if (buf == curbuf)
-           apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf);
+       buf_freeall(buf, BFA_WIPE | BFA_DEL);
+       if (buf != curbuf)   // autocommands deleted the buffer!
+           return NULL;
 #ifdef FEAT_EVAL
        if (aborting())         // autocmds may abort script processing
        {
@@ -2079,12 +2078,6 @@ buflist_new(
            return NULL;
        }
 #endif
-       if (buf == curbuf)
-       {
-           // Make sure 'bufhidden' and 'buftype' are empty
-           clear_string_option(&buf->b_p_bh);
-           clear_string_option(&buf->b_p_bt);
-       }
     }
     if (buf != curbuf || curbuf == NULL)
     {
@@ -2132,14 +2125,6 @@ buflist_new(
 
     if (buf == curbuf)
     {
-       // free all things allocated for this buffer
-       buf_freeall(buf, 0);
-       if (buf != curbuf)       // autocommands deleted the buffer!
-           return NULL;
-#if defined(FEAT_EVAL)
-       if (aborting())         // autocmds may abort script processing
-           return NULL;
-#endif
        free_buffer_stuff(buf, FALSE);  // delete local variables et al.
 
        // Init the options.
index 724d0733fc958f73c93734e6d132b730c2aa55ce..fd3631791ad34da789efe6af8b12f6cd6ae4bae1 100644 (file)
@@ -3037,9 +3037,10 @@ func Test_autocmd_closing_cmdwin()
 endfunc
 
 func Test_autocmd_vimgrep()
+  %bwipe!
   augroup aucmd_vimgrep
-    au QuickfixCmdPre,BufNew,BufDelete,BufReadCmd * sb
-    au QuickfixCmdPre,BufNew,BufDelete,BufReadCmd * q9\0
+    au QuickfixCmdPre,BufNew,BufReadCmd * sb
+    au QuickfixCmdPre,BufNew,BufReadCmd * q9\0
   augroup END
   %bwipe!
   call assert_fails('lv ?a? foo', 'E926:')
@@ -3160,4 +3161,22 @@ func Test_v_event_readonly()
 endfunc
 
 
+func Test_noname_autocmd()
+  augroup test_noname_autocmd_group
+    autocmd!
+    autocmd BufEnter * call add(s:li, ["BufEnter", expand("<afile>")])
+    autocmd BufDelete * call add(s:li, ["BufDelete", expand("<afile>")])
+    autocmd BufLeave * call add(s:li, ["BufLeave", expand("<afile>")])
+    autocmd BufUnload * call add(s:li, ["BufUnload", expand("<afile>")])
+    autocmd BufWipeout * call add(s:li, ["BufWipeout", expand("<afile>")])
+  augroup END
+
+  let s:li = []
+  edit foo
+  call assert_equal([['BufUnload', ''], ['BufDelete', ''], ['BufWipeout', ''], ['BufEnter', 'foo']], s:li)
+
+  au! test_noname_autocmd_group
+  augroup! test_noname_autocmd_group
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9a76fdf383e00ce02ab8c59106709d81f4bf94b6..b00e0e832a92b15e590bdfc5fcd899875e80dd5c 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4791,
 /**/
     4790,
 /**/