diff src/buffer.c @ 28534:2d600e916978 v8.2.4791

patch 8.2.4791: events triggered in different order when reusing buffer Commit: https://github.com/vim/vim/commit/fef4485ef58d5937b170c6dc69431359469fc9cd Author: Charlie Groves <charlie.groves@gmail.com> Date: Tue Apr 19 16:24:12 2022 +0100 patch 8.2.4791: events triggered in different order when reusing buffer Problem: Autocmd events triggered in different order when reusing an empty buffer. Solution: Call buff_freeall() earlier. (Charlie Groves, closes #10198)
author Bram Moolenaar <Bram@vim.org>
date Tue, 19 Apr 2022 17:30:03 +0200
parents 1170b35651a5
children 6e55b7b30df5
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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.