From 8f3245dbfa91d384215c78da32e4d1739c8a1f34 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Apr 2022 21:58:35 +0800 Subject: refactor(window): cherry-pick win_close_buffer() from Vim patch 8.1.1391 --- src/nvim/window.c | 66 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index cc21bf25b0..e471c0b304 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2541,6 +2541,41 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev return true; } +/// Close the buffer of "win" and unload it if "free_buf" is true. +/// "abort_if_last" is passed to close_buffer(): abort closing if all other +/// windows are closed. +static void win_close_buffer(win_T *win, bool free_buf, bool abort_if_last) +{ + // Free independent synblock before the buffer is freed. + if (win->w_buffer != NULL) { + reset_synblock(win); + } + + // When a quickfix/location list window is closed and the buffer is + // displayed in only one window, then unlist the buffer. + if (win->w_buffer != NULL && bt_quickfix(win->w_buffer) + && win->w_buffer->b_nwindows == 1) { + win->w_buffer->b_p_bl = false; + } + + // Close the link to the buffer. + if (win->w_buffer != NULL) { + bufref_T bufref; + set_bufref(&bufref, curbuf); + win->w_closing = true; + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, abort_if_last); + if (win_valid_any_tab(win)) { + win->w_closing = false; + } + + // Make sure curbuf is valid. It can become invalid if 'bufhidden' is + // "wipe". + if (!bufref_valid(&bufref)) { + curbuf = firstbuf; + } + } +} + // Close window "win". Only works for the current tab page. // If "free_buf" is true related buffer may be unloaded. // @@ -2679,36 +2714,7 @@ int win_close(win_T *win, bool free_buf, bool force) return OK; } - // Free independent synblock before the buffer is freed. - if (win->w_buffer != NULL) { - reset_synblock(win); - } - - // When a quickfix/location list window is closed and the buffer is - // displayed in only one window, then unlist the buffer. - if (win->w_buffer != NULL && bt_quickfix(win->w_buffer) - && win->w_buffer->b_nwindows == 1) { - win->w_buffer->b_p_bl = false; - } - - /* - * Close the link to the buffer. - */ - if (win->w_buffer != NULL) { - bufref_T bufref; - set_bufref(&bufref, curbuf); - win->w_closing = true; - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, true); - if (win_valid_any_tab(win)) { - win->w_closing = false; - } - - // Make sure curbuf is valid. It can become invalid if 'bufhidden' is - // "wipe". - if (!bufref_valid(&bufref)) { - curbuf = firstbuf; - } - } + win_close_buffer(win, free_buf, true); if (only_one_window() && win_valid(win) && win->w_buffer == NULL && (last_window(win) || curtab != prev_curtab -- cgit From 44b59d1a696b35d2520dbea2de3aab01e740a7ca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Apr 2022 21:46:07 +0800 Subject: vim-patch:8.2.0004: get E685 and E931 if buffer reload is interrupted Problem: Get E685 and E931 if buffer reload is interrupted. Solution: Do not abort deleting a dummy buffer. (closes vim/vim#5361) https://github.com/vim/vim/commit/a6e8f888e7fc31b8ab7233509254fb2e2fe4089f --- src/nvim/window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index e471c0b304..20f2447bbe 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2563,7 +2563,7 @@ static void win_close_buffer(win_T *win, bool free_buf, bool abort_if_last) bufref_T bufref; set_bufref(&bufref, curbuf); win->w_closing = true; - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, abort_if_last); + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, abort_if_last, false); if (win_valid_any_tab(win)) { win->w_closing = false; } @@ -2885,7 +2885,7 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) if (win->w_buffer != NULL) { // Close the link to the buffer. - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, false); + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, false, false); } // Careful: Autocommands may have closed the tab page or made it the -- cgit From b7bc931f631febeeffee528cc3b5667cfbf60a90 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Apr 2022 07:57:50 +0800 Subject: vim-patch:8.2.4700: buffer remains active if WinClosed event throws an exception Problem: Buffer remains active if a WinClosed event throws an exception. Solution: Ignore aborting() when closing the buffer. (closes vim/vim#10097) https://github.com/vim/vim/commit/c947b9ae419114ebfef9725814ea41a466fcf879 --- src/nvim/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 20f2447bbe..21350f1a38 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2563,7 +2563,7 @@ static void win_close_buffer(win_T *win, bool free_buf, bool abort_if_last) bufref_T bufref; set_bufref(&bufref, curbuf); win->w_closing = true; - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, abort_if_last, false); + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, abort_if_last, true); if (win_valid_any_tab(win)) { win->w_closing = false; } -- cgit From 191f009ab74111bab6e60ffc1dac5484196b7a6b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Apr 2022 07:58:34 +0800 Subject: vim-patch:8.2.4706: buffer remains active with WinClosed and tabpages Problem: Buffer remains active if a WinClosed event throws an exception when there are multiple tabpages. Solution: Ignore aborting() when closing the buffer. (closes vim/vim#10101) https://github.com/vim/vim/commit/6a06940f8ae7283999c83ccdf268540220573105 --- src/nvim/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 21350f1a38..9aa2f947cb 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2885,7 +2885,7 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) if (win->w_buffer != NULL) { // Close the link to the buffer. - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, false, false); + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, false, true); } // Careful: Autocommands may have closed the tab page or made it the -- cgit