comparison src/window.c @ 26117:d4d9c7c55a5f v8.2.3591

patch 8.2.3591: no event is triggered when closing a window Commit: https://github.com/vim/vim/commit/23beefed73aadb243fb67cf944e3d60fe8c038bb Author: naohiro ono <obcat@icloud.com> Date: Sat Nov 13 12:38:49 2021 +0000 patch 8.2.3591: no event is triggered when closing a window Problem: No event is triggered when closing a window. Solution: Add the WinClosed event. (Naohiro Ono, closes https://github.com/vim/vim/issues/9110)
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Nov 2021 13:45:03 +0100
parents ad90d7eee236
children 2c64a420ce7e
comparison
equal deleted inserted replaced
26116:9007076c18da 26117:d4d9c7c55a5f
17 static void frame_setwidth(frame_T *curfrp, int width); 17 static void frame_setwidth(frame_T *curfrp, int width);
18 static void win_exchange(long); 18 static void win_exchange(long);
19 static void win_rotate(int, int); 19 static void win_rotate(int, int);
20 static void win_totop(int size, int flags); 20 static void win_totop(int size, int flags);
21 static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height); 21 static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height);
22 static void trigger_winclosed(win_T *win);
22 static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp); 23 static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp);
23 static frame_T *win_altframe(win_T *win, tabpage_T *tp); 24 static frame_T *win_altframe(win_T *win, tabpage_T *tp);
24 static tabpage_T *alt_tabpage(void); 25 static tabpage_T *alt_tabpage(void);
25 static win_T *frame2win(frame_T *frp); 26 static win_T *frame2win(frame_T *frp);
26 static int frame_has_win(frame_T *frp, win_T *wp); 27 static int frame_has_win(frame_T *frp, win_T *wp);
2564 2565
2565 #ifdef FEAT_PROP_POPUP 2566 #ifdef FEAT_PROP_POPUP
2566 if (popup_win_closed(win) && !win_valid(win)) 2567 if (popup_win_closed(win) && !win_valid(win))
2567 return FAIL; 2568 return FAIL;
2568 #endif 2569 #endif
2570
2571 // Trigger WinClosed just before starting to free window-related resources.
2572 trigger_winclosed(win);
2573 // autocmd may have freed the window already.
2574 if (!win_valid_any_tab(win))
2575 return OK;
2576
2569 win_close_buffer(win, free_buf ? DOBUF_UNLOAD : 0, TRUE); 2577 win_close_buffer(win, free_buf ? DOBUF_UNLOAD : 0, TRUE);
2570 2578
2571 if (only_one_window() && win_valid(win) && win->w_buffer == NULL 2579 if (only_one_window() && win_valid(win) && win->w_buffer == NULL
2572 && (last_window() || curtab != prev_curtab 2580 && (last_window() || curtab != prev_curtab
2573 || close_last_window_tabpage(win, free_buf, prev_curtab))) 2581 || close_last_window_tabpage(win, free_buf, prev_curtab)))
2708 2716
2709 redraw_all_later(NOT_VALID); 2717 redraw_all_later(NOT_VALID);
2710 return OK; 2718 return OK;
2711 } 2719 }
2712 2720
2721 static void
2722 trigger_winclosed(win_T *win)
2723 {
2724 static int recursive = FALSE;
2725 char_u winid[NUMBUFLEN];
2726
2727 if (recursive)
2728 return;
2729 recursive = TRUE;
2730 vim_snprintf((char *)winid, sizeof(winid), "%i", win->w_id);
2731 apply_autocmds(EVENT_WINCLOSED, winid, winid, FALSE, win->w_buffer);
2732 recursive = FALSE;
2733 }
2734
2713 /* 2735 /*
2714 * Close window "win" in tab page "tp", which is not the current tab page. 2736 * Close window "win" in tab page "tp", which is not the current tab page.
2715 * This may be the last window in that tab page and result in closing the tab, 2737 * This may be the last window in that tab page and result in closing the tab,
2716 * thus "tp" may become invalid! 2738 * thus "tp" may become invalid!
2717 * Caller must check if buffer is hidden and whether the tabline needs to be 2739 * Caller must check if buffer is hidden and whether the tabline needs to be
2728 // Get here with win->w_buffer == NULL when win_close() detects the tab 2750 // Get here with win->w_buffer == NULL when win_close() detects the tab
2729 // page changed. 2751 // page changed.
2730 if (win->w_closing || (win->w_buffer != NULL 2752 if (win->w_closing || (win->w_buffer != NULL
2731 && win->w_buffer->b_locked > 0)) 2753 && win->w_buffer->b_locked > 0))
2732 return; // window is already being closed 2754 return; // window is already being closed
2755
2756 // Trigger WinClosed just before starting to free window-related resources.
2757 trigger_winclosed(win);
2758 // autocmd may have freed the window already.
2759 if (!win_valid_any_tab(win))
2760 return;
2733 2761
2734 if (win->w_buffer != NULL) 2762 if (win->w_buffer != NULL)
2735 // Close the link to the buffer. 2763 // Close the link to the buffer.
2736 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, 2764 close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0,
2737 FALSE, FALSE); 2765 FALSE, FALSE);