diff options
author | naohiro ono <obcat@icloud.com> | 2021-11-13 12:38:49 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-11-13 12:38:49 +0000 |
commit | 23beefed73aadb243fb67cf944e3d60fe8c038bb (patch) | |
tree | 8d03d8a6bc3126588a637252bd1a23e53baeaabf /src/window.c | |
parent | a0fca17251bf491db7b8d302ce22dee844597e82 (diff) | |
download | vim-git-23beefed73aadb243fb67cf944e3d60fe8c038bb.tar.gz |
patch 8.2.3591: no event is triggered when closing a windowv8.2.3591
Problem: No event is triggered when closing a window.
Solution: Add the WinClosed event. (Naohiro Ono, closes #9110)
Diffstat (limited to 'src/window.c')
-rw-r--r-- | src/window.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c index 5de6ed7f5..226d6c1a4 100644 --- a/src/window.c +++ b/src/window.c @@ -19,6 +19,7 @@ static void win_exchange(long); static void win_rotate(int, int); static void win_totop(int size, int flags); static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height); +static void trigger_winclosed(win_T *win); static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp); static frame_T *win_altframe(win_T *win, tabpage_T *tp); static tabpage_T *alt_tabpage(void); @@ -2566,6 +2567,13 @@ win_close(win_T *win, int free_buf) if (popup_win_closed(win) && !win_valid(win)) return FAIL; #endif + + // Trigger WinClosed just before starting to free window-related resources. + trigger_winclosed(win); + // autocmd may have freed the window already. + if (!win_valid_any_tab(win)) + return OK; + win_close_buffer(win, free_buf ? DOBUF_UNLOAD : 0, TRUE); if (only_one_window() && win_valid(win) && win->w_buffer == NULL @@ -2710,6 +2718,20 @@ win_close(win_T *win, int free_buf) return OK; } + static void +trigger_winclosed(win_T *win) +{ + static int recursive = FALSE; + char_u winid[NUMBUFLEN]; + + if (recursive) + return; + recursive = TRUE; + vim_snprintf((char *)winid, sizeof(winid), "%i", win->w_id); + apply_autocmds(EVENT_WINCLOSED, winid, winid, FALSE, win->w_buffer); + recursive = FALSE; +} + /* * Close window "win" in tab page "tp", which is not the current tab page. * This may be the last window in that tab page and result in closing the tab, @@ -2731,6 +2753,12 @@ win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) && win->w_buffer->b_locked > 0)) return; // window is already being closed + // Trigger WinClosed just before starting to free window-related resources. + trigger_winclosed(win); + // autocmd may have freed the window already. + if (!win_valid_any_tab(win)) + return; + if (win->w_buffer != NULL) // Close the link to the buffer. close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, |