diff options
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 373ff8feda..41d8e5d914 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2305,10 +2305,19 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // If the current buffer was empty and has no file name, curbuf // is returned by buflist_new(), nothing to do here. if (buf != curbuf) { + // Should only be possible to get here if the cmdwin is closed, or + // if it's opening and its buffer hasn't been set yet (the new + // buffer is for it). + assert(cmdwin_buf == NULL); + const int save_cmdwin_type = cmdwin_type; + win_T *const save_cmdwin_win = cmdwin_win; + win_T *const save_cmdwin_old_curwin = cmdwin_old_curwin; // BufLeave applies to the old buffer. cmdwin_type = 0; + cmdwin_win = NULL; + cmdwin_old_curwin = NULL; // Be careful: The autocommands may delete any buffer and change // the current buffer. @@ -2324,7 +2333,11 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum const bufref_T save_au_new_curbuf = au_new_curbuf; set_bufref(&au_new_curbuf, buf); apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf); + cmdwin_type = save_cmdwin_type; + cmdwin_win = save_cmdwin_win; + cmdwin_old_curwin = save_cmdwin_old_curwin; + if (!bufref_valid(&au_new_curbuf)) { // New buffer has been deleted. delbuf_msg(new_name); // Frees new_name. |