comparison src/window.c @ 25501:a1ed55c02e80 v8.2.3287

patch 8.2.3287: channel events not handled in BufEnter autocommand Commit: https://github.com/vim/vim/commit/57942237c1d54d8a236b43c56dc2b002339eb394 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 4 20:54:55 2021 +0200 patch 8.2.3287: channel events not handled in BufEnter autocommand Problem: Channel events not handled in BufEnter autocommand. Solution: Decrement dont_parse_messages earlier. (Tim Pope, closes https://github.com/vim/vim/issues/8697)
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Aug 2021 21:00:05 +0200
parents 5ebf9bb1cbcd
children 040a45d39570
comparison
equal deleted inserted replaced
25500:4b868f9f92e6 25501:a1ed55c02e80
38 static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds); 38 static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds);
39 static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds); 39 static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds);
40 static void frame_fix_height(win_T *wp); 40 static void frame_fix_height(win_T *wp);
41 static int frame_minheight(frame_T *topfrp, win_T *next_curwin); 41 static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
42 static int may_open_tabpage(void); 42 static int may_open_tabpage(void);
43 static void win_enter_ext(win_T *wp, int flags); 43 static int win_enter_ext(win_T *wp, int flags);
44 static void win_free(win_T *wp, tabpage_T *tp); 44 static void win_free(win_T *wp, tabpage_T *tp);
45 static int win_unlisted(win_T *wp); 45 static int win_unlisted(win_T *wp);
46 static void win_append(win_T *after, win_T *wp); 46 static void win_append(win_T *after, win_T *wp);
47 static void frame_append(frame_T *after, frame_T *frp); 47 static void frame_append(frame_T *after, frame_T *frp);
48 static void frame_insert(frame_T *before, frame_T *frp); 48 static void frame_insert(frame_T *before, frame_T *frp);
71 #define WEE_UNDO_SYNC 0x01 71 #define WEE_UNDO_SYNC 0x01
72 #define WEE_CURWIN_INVALID 0x02 72 #define WEE_CURWIN_INVALID 0x02
73 #define WEE_TRIGGER_NEW_AUTOCMDS 0x04 73 #define WEE_TRIGGER_NEW_AUTOCMDS 0x04
74 #define WEE_TRIGGER_ENTER_AUTOCMDS 0x08 74 #define WEE_TRIGGER_ENTER_AUTOCMDS 0x08
75 #define WEE_TRIGGER_LEAVE_AUTOCMDS 0x10 75 #define WEE_TRIGGER_LEAVE_AUTOCMDS 0x10
76 #define WEE_ALLOW_PARSE_MESSAGES 0x20
76 77
77 static char *m_onlyone = N_("Already only one window"); 78 static char *m_onlyone = N_("Already only one window");
78 79
79 // When non-zero splitting a window is forbidden. Used to avoid that nasty 80 // When non-zero splitting a window is forbidden. Used to avoid that nasty
80 // autocommands mess up the window structure. 81 // autocommands mess up the window structure.
1336 #endif 1337 #endif
1337 1338
1338 /* 1339 /*
1339 * make the new window the current window 1340 * make the new window the current window
1340 */ 1341 */
1341 win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS 1342 (void)win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS
1342 | WEE_TRIGGER_LEAVE_AUTOCMDS); 1343 | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
1343 if (flags & WSP_VERT) 1344 if (flags & WSP_VERT)
1344 p_wiw = i; 1345 p_wiw = i;
1345 else 1346 else
1346 p_wh = i; 1347 p_wh = i;
1347 1348
2481 tabpage_T *prev_curtab = curtab; 2482 tabpage_T *prev_curtab = curtab;
2482 frame_T *win_frame = win->w_frame->fr_parent; 2483 frame_T *win_frame = win->w_frame->fr_parent;
2483 #ifdef FEAT_DIFF 2484 #ifdef FEAT_DIFF
2484 int had_diffmode = win->w_p_diff; 2485 int had_diffmode = win->w_p_diff;
2485 #endif 2486 #endif
2487 int did_decrement = FALSE;
2486 2488
2487 #if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP) 2489 #if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP)
2488 // Can close a popup window with a terminal if the job has finished. 2490 // Can close a popup window with a terminal if the job has finished.
2489 if (may_close_term_popup() == OK) 2491 if (may_close_term_popup() == OK)
2490 return OK; 2492 return OK;
2659 win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); 2661 win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir);
2660 else 2662 else
2661 win_comp_pos(); 2663 win_comp_pos();
2662 if (close_curwin) 2664 if (close_curwin)
2663 { 2665 {
2664 win_enter_ext(wp, WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS 2666 // Pass WEE_ALLOW_PARSE_MESSAGES to decrement dont_parse_messages
2665 | WEE_TRIGGER_LEAVE_AUTOCMDS); 2667 // before autocommands.
2668 did_decrement = win_enter_ext(wp,
2669 WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS
2670 | WEE_TRIGGER_LEAVE_AUTOCMDS | WEE_ALLOW_PARSE_MESSAGES);
2666 if (other_buffer) 2671 if (other_buffer)
2667 // careful: after this wp and win may be invalid! 2672 // careful: after this wp and win may be invalid!
2668 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); 2673 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
2669 } 2674 }
2670 2675
2671 --split_disallowed; 2676 --split_disallowed;
2672 #ifdef MESSAGE_QUEUE 2677 #ifdef MESSAGE_QUEUE
2673 --dont_parse_messages; 2678 if (!did_decrement)
2679 --dont_parse_messages;
2674 #endif 2680 #endif
2675 2681
2676 /* 2682 /*
2677 * If last window has a status line now and we don't want one, 2683 * If last window has a status line now and we don't want one,
2678 * remove the status line. 2684 * remove the status line.
4186 topframe = tp->tp_topframe; 4192 topframe = tp->tp_topframe;
4187 4193
4188 // We would like doing the TabEnter event first, but we don't have a 4194 // We would like doing the TabEnter event first, but we don't have a
4189 // valid current window yet, which may break some commands. 4195 // valid current window yet, which may break some commands.
4190 // This triggers autocommands, thus may make "tp" invalid. 4196 // This triggers autocommands, thus may make "tp" invalid.
4191 win_enter_ext(tp->tp_curwin, WEE_CURWIN_INVALID 4197 (void)win_enter_ext(tp->tp_curwin, WEE_CURWIN_INVALID
4192 | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0) 4198 | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0)
4193 | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0)); 4199 | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0));
4194 prevwin = next_prevwin; 4200 prevwin = next_prevwin;
4195 4201
4196 last_status(FALSE); // status line may appear or disappear 4202 last_status(FALSE); // status line may appear or disappear
4474 if (curwin->w_p_cole > 0 && !msg_scrolled) 4480 if (curwin->w_p_cole > 0 && !msg_scrolled)
4475 need_cursor_line_redraw = TRUE; 4481 need_cursor_line_redraw = TRUE;
4476 #endif 4482 #endif
4477 } 4483 }
4478 4484
4479 #if defined(FEAT_PERL) || defined(PROTO) 4485 #if defined(FEAT_PERL) || defined(FEAT_LUA) || defined(PROTO)
4480 /* 4486 /*
4481 * Find window number "winnr" (counting top to bottom). 4487 * Find window number "winnr" (counting top to bottom).
4482 */ 4488 */
4483 win_T * 4489 win_T *
4484 win_find_nr(int winnr) 4490 win_find_nr(int winnr)
4687 * Make window "wp" the current window. 4693 * Make window "wp" the current window.
4688 */ 4694 */
4689 void 4695 void
4690 win_enter(win_T *wp, int undo_sync) 4696 win_enter(win_T *wp, int undo_sync)
4691 { 4697 {
4692 win_enter_ext(wp, (undo_sync ? WEE_UNDO_SYNC : 0) 4698 (void)win_enter_ext(wp, (undo_sync ? WEE_UNDO_SYNC : 0)
4693 | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS); 4699 | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
4694 } 4700 }
4695 4701
4696 /* 4702 /*
4697 * Make window "wp" the current window. 4703 * Make window "wp" the current window.
4698 * Can be called with "flags" containing WEE_CURWIN_INVALID, which means that 4704 * Can be called with "flags" containing WEE_CURWIN_INVALID, which means that
4699 * curwin has just been closed and isn't valid. 4705 * curwin has just been closed and isn't valid.
4700 */ 4706 * Returns TRUE when dont_parse_messages was decremented.
4701 static void 4707 */
4708 static int
4702 win_enter_ext(win_T *wp, int flags) 4709 win_enter_ext(win_T *wp, int flags)
4703 { 4710 {
4704 int other_buffer = FALSE; 4711 int other_buffer = FALSE;
4705 int curwin_invalid = (flags & WEE_CURWIN_INVALID); 4712 int curwin_invalid = (flags & WEE_CURWIN_INVALID);
4713 int did_decrement = FALSE;
4706 4714
4707 if (wp == curwin && !curwin_invalid) // nothing to do 4715 if (wp == curwin && !curwin_invalid) // nothing to do
4708 return; 4716 return FALSE;
4709 4717
4710 #ifdef FEAT_JOB_CHANNEL 4718 #ifdef FEAT_JOB_CHANNEL
4711 if (!curwin_invalid) 4719 if (!curwin_invalid)
4712 leaving_window(curwin); 4720 leaving_window(curwin);
4713 #endif 4721 #endif
4720 if (wp->w_buffer != curbuf) 4728 if (wp->w_buffer != curbuf)
4721 { 4729 {
4722 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); 4730 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
4723 other_buffer = TRUE; 4731 other_buffer = TRUE;
4724 if (!win_valid(wp)) 4732 if (!win_valid(wp))
4725 return; 4733 return FALSE;
4726 } 4734 }
4727 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf); 4735 apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
4728 if (!win_valid(wp)) 4736 if (!win_valid(wp))
4729 return; 4737 return FALSE;
4730 #ifdef FEAT_EVAL 4738 #ifdef FEAT_EVAL
4731 // autocmds may abort script processing 4739 // autocmds may abort script processing
4732 if (aborting()) 4740 if (aborting())
4733 return; 4741 return FALSE;
4734 #endif 4742 #endif
4735 } 4743 }
4736 4744
4737 // sync undo before leaving the current buffer 4745 // sync undo before leaving the current buffer
4738 if ((flags & WEE_UNDO_SYNC) && curbuf != wp->w_buffer) 4746 if ((flags & WEE_UNDO_SYNC) && curbuf != wp->w_buffer)
4755 check_cursor(); 4763 check_cursor();
4756 if (!virtual_active()) 4764 if (!virtual_active())
4757 curwin->w_cursor.coladd = 0; 4765 curwin->w_cursor.coladd = 0;
4758 changed_line_abv_curs(); // assume cursor position needs updating 4766 changed_line_abv_curs(); // assume cursor position needs updating
4759 4767
4768 // Now it is OK to parse messages again, which may be needed in
4769 // autocommands.
4770 #ifdef MESSAGE_QUEUE
4771 if (flags & WEE_ALLOW_PARSE_MESSAGES)
4772 {
4773 --dont_parse_messages;
4774 did_decrement = TRUE;
4775 }
4776 #endif
4777
4760 if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL) 4778 if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
4761 { 4779 {
4762 char_u *dirname; 4780 char_u *dirname;
4763 4781
4764 // Window or tab has a local directory: Save current directory as 4782 // Window or tab has a local directory: Save current directory as
4830 4848
4831 setmouse(); // in case jumped to/from help buffer 4849 setmouse(); // in case jumped to/from help buffer
4832 4850
4833 // Change directories when the 'acd' option is set. 4851 // Change directories when the 'acd' option is set.
4834 DO_AUTOCHDIR; 4852 DO_AUTOCHDIR;
4853
4854 return did_decrement;
4835 } 4855 }
4836 4856
4837 4857
4838 /* 4858 /*
4839 * Jump to the first open window that contains buffer "buf", if one exists. 4859 * Jump to the first open window that contains buffer "buf", if one exists.