diff src/buffer.c @ 10114:aa2219afd1c2 v7.4.2328

commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 4 21:33:09 2016 +0200 patch 7.4.2328 Problem: Crash when BufWinLeave autocmd goes to another tab page. (Hirohito Higashi) Solution: Make close_buffer() go back to the right window.
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Sep 2016 21:45:06 +0200
parents 7cb49e98d582
children 5d77565e6222
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -450,6 +450,11 @@ close_buffer(
     int		is_curbuf;
     int		nwindows;
     bufref_T	bufref;
+# ifdef FEAT_WINDOWS
+    int		is_curwin = (curwin!= NULL && curwin->w_buffer == buf);
+    win_T	*the_curwin = curwin;
+    tabpage_T	*the_curtab = curtab;
+# endif
 #endif
     int		unload_buf = (action != 0);
     int		del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
@@ -544,6 +549,19 @@ aucmd_abort:
 	    return;
 # endif
     }
+
+# ifdef FEAT_WINDOWS
+    /* If the buffer was in curwin and the window has changed, go back to that
+     * window, if it still exists.  This avoids that ":edit x" triggering a
+     * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */
+    if (is_curwin && curwin != the_curwin &&  win_valid_any_tab(the_curwin))
+    {
+	block_autocmds();
+	goto_tabpage_win(the_curtab, the_curwin);
+	unblock_autocmds();
+    }
+# endif
+
     nwindows = buf->b_nwindows;
 #endif