diff options
author | Grzegorz Milka <grzegorzmilka@gmail.com> | 2016-10-18 02:02:47 +0200 |
---|---|---|
committer | Grzegorz Milka <grzegorzmilka@gmail.com> | 2016-10-23 00:41:45 +0200 |
commit | 9755a2ffd5727c7fc0576e60a21368618978c504 (patch) | |
tree | 573e946bce3ebb9380e1a9e2d7ed461341ea16ea /src/nvim/buffer.c | |
parent | c5c8a821341b71ae29786c97df7930a9581f7ab7 (diff) | |
download | rneovim-9755a2ffd5727c7fc0576e60a21368618978c504.tar.gz rneovim-9755a2ffd5727c7fc0576e60a21368618978c504.tar.bz2 rneovim-9755a2ffd5727c7fc0576e60a21368618978c504.zip |
vim-patch:7.4.2312
Problem: Crash when autocommand moves to another tab. (Dominique Pelle)
Solution: When navigating to another window halfway the :edit command go
back to the right window.
https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 176967ad2a..fc6e46cf64 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -478,17 +478,20 @@ void buf_clear_file(buf_T *buf) buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */ } -/* - * buf_freeall() - free all things allocated for a buffer that are related to - * the file. flags: - * BFA_DEL buffer is going to be deleted - * BFA_WIPE buffer is going to be wiped out - * BFA_KEEP_UNDO do not free undo information - */ +/// buf_freeall() - free all things allocated for a buffer that are related to +/// the file. Careful: get here with "curwin" NULL when exiting. +/// +/// @param flags BFA_DEL buffer is going to be deleted +/// BFA_WIPE buffer is going to be wiped out +/// BFA_KEEP_UNDO do not free undo information void buf_freeall(buf_T *buf, int flags) { bool is_curbuf = (buf == curbuf); + int is_curwin = (curwin != NULL && curwin->w_buffer == buf); + win_T *the_curwin = curwin; + tabpage_T *the_curtab = curtab; + // Make sure the buffer isn't closed by autocommands. buf->b_closing = true; apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); if (!buf_valid(buf)) /* autocommands may delete the buffer */ @@ -505,6 +508,15 @@ void buf_freeall(buf_T *buf, int flags) return; } buf->b_closing = false; + + // 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(); + } if (aborting()) /* autocmds may abort script processing */ return; |