@@ -40,7 +40,7 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
4040static void frame_fix_height (win_T * wp );
4141static int frame_minheight (frame_T * topfrp , win_T * next_curwin );
4242static 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 );
4444static void win_free (win_T * wp , tabpage_T * tp );
4545static int win_unlisted (win_T * wp );
4646static void win_append (win_T * after , win_T * wp );
@@ -73,6 +73,7 @@ static win_T *win_alloc(win_T *after, int hidden);
7373#define WEE_TRIGGER_NEW_AUTOCMDS 0x04
7474#define WEE_TRIGGER_ENTER_AUTOCMDS 0x08
7575#define WEE_TRIGGER_LEAVE_AUTOCMDS 0x10
76+ #define WEE_ALLOW_PARSE_MESSAGES 0x20
7677
7778static char * m_onlyone = N_ ("Already only one window" );
7879
@@ -1338,8 +1339,8 @@ win_split_ins(
13381339 /*
13391340 * make the new window the current window
13401341 */
1341- win_enter_ext (wp , WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS
1342- | WEE_TRIGGER_LEAVE_AUTOCMDS );
1342+ ( void ) win_enter_ext (wp , WEE_TRIGGER_NEW_AUTOCMDS
1343+ | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS );
13431344 if (flags & WSP_VERT )
13441345 p_wiw = i ;
13451346 else
@@ -2483,6 +2484,7 @@ win_close(win_T *win, int free_buf)
24832484#ifdef FEAT_DIFF
24842485 int had_diffmode = win -> w_p_diff ;
24852486#endif
2487+ int did_decrement = FALSE;
24862488
24872489#if defined(FEAT_TERMINAL ) && defined(FEAT_PROP_POPUP )
24882490 // Can close a popup window with a terminal if the job has finished.
@@ -2661,16 +2663,20 @@ win_close(win_T *win, int free_buf)
26612663 win_comp_pos ();
26622664 if (close_curwin )
26632665 {
2664- win_enter_ext (wp , WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS
2665- | WEE_TRIGGER_LEAVE_AUTOCMDS );
2666+ // Pass WEE_ALLOW_PARSE_MESSAGES to decrement dont_parse_messages
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 );
26662671 if (other_buffer )
26672672 // careful: after this wp and win may be invalid!
26682673 apply_autocmds (EVENT_BUFENTER , NULL , NULL , FALSE, curbuf );
26692674 }
26702675
26712676 -- split_disallowed ;
26722677#ifdef MESSAGE_QUEUE
2673- -- dont_parse_messages ;
2678+ if (!did_decrement )
2679+ -- dont_parse_messages ;
26742680#endif
26752681
26762682 /*
@@ -4188,7 +4194,7 @@ enter_tabpage(
41884194 // We would like doing the TabEnter event first, but we don't have a
41894195 // valid current window yet, which may break some commands.
41904196 // 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
41924198 | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0 )
41934199 | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0 ));
41944200 prevwin = next_prevwin ;
@@ -4476,7 +4482,7 @@ win_goto(win_T *wp)
44764482#endif
44774483}
44784484
4479- #if defined(FEAT_PERL ) || defined(PROTO )
4485+ #if defined(FEAT_PERL ) || defined(FEAT_LUA ) || defined( PROTO )
44804486/*
44814487 * Find window number "winnr" (counting top to bottom).
44824488 */
@@ -4689,23 +4695,25 @@ win_goto_hor(
46894695 void
46904696win_enter (win_T * wp , int undo_sync )
46914697{
4692- win_enter_ext (wp , (undo_sync ? WEE_UNDO_SYNC : 0 )
4698+ ( void ) win_enter_ext (wp , (undo_sync ? WEE_UNDO_SYNC : 0 )
46934699 | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS );
46944700}
46954701
46964702/*
46974703 * Make window "wp" the current window.
46984704 * Can be called with "flags" containing WEE_CURWIN_INVALID, which means that
46994705 * curwin has just been closed and isn't valid.
4706+ * Returns TRUE when dont_parse_messages was decremented.
47004707 */
4701- static void
4708+ static int
47024709win_enter_ext (win_T * wp , int flags )
47034710{
47044711 int other_buffer = FALSE;
47054712 int curwin_invalid = (flags & WEE_CURWIN_INVALID );
4713+ int did_decrement = FALSE;
47064714
47074715 if (wp == curwin && !curwin_invalid ) // nothing to do
4708- return ;
4716+ return FALSE ;
47094717
47104718#ifdef FEAT_JOB_CHANNEL
47114719 if (!curwin_invalid )
@@ -4722,15 +4730,15 @@ win_enter_ext(win_T *wp, int flags)
47224730 apply_autocmds (EVENT_BUFLEAVE , NULL , NULL , FALSE, curbuf );
47234731 other_buffer = TRUE;
47244732 if (!win_valid (wp ))
4725- return ;
4733+ return FALSE ;
47264734 }
47274735 apply_autocmds (EVENT_WINLEAVE , NULL , NULL , FALSE, curbuf );
47284736 if (!win_valid (wp ))
4729- return ;
4737+ return FALSE ;
47304738#ifdef FEAT_EVAL
47314739 // autocmds may abort script processing
47324740 if (aborting ())
4733- return ;
4741+ return FALSE ;
47344742#endif
47354743 }
47364744
@@ -4757,6 +4765,16 @@ win_enter_ext(win_T *wp, int flags)
47574765 curwin -> w_cursor .coladd = 0 ;
47584766 changed_line_abv_curs (); // assume cursor position needs updating
47594767
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+
47604778 if (curwin -> w_localdir != NULL || curtab -> tp_localdir != NULL )
47614779 {
47624780 char_u * dirname ;
@@ -4832,6 +4850,8 @@ win_enter_ext(win_T *wp, int flags)
48324850
48334851 // Change directories when the 'acd' option is set.
48344852 DO_AUTOCHDIR ;
4853+
4854+ return did_decrement ;
48354855}
48364856
48374857
0 commit comments