Patch 8.2.3287
Problem:    Channel events not handled in BufEnter autocommand.
Solution:   Decrement dont_parse_messages earlier. (Tim Pope, closes #8697)
Files:      src/window.c, src/testdir/test_channel.vim


*** ../vim-8.2.3286/src/window.c        2021-08-04 20:26:16.034253844 +0200
--- src/window.c        2021-08-04 20:51:34.094468213 +0200
***************
*** 40,46 ****
  static void frame_fix_height(win_T *wp);
  static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
  static int may_open_tabpage(void);
! static void win_enter_ext(win_T *wp, int flags);
  static void win_free(win_T *wp, tabpage_T *tp);
  static int win_unlisted(win_T *wp);
  static void win_append(win_T *after, win_T *wp);
--- 40,46 ----
  static void frame_fix_height(win_T *wp);
  static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
  static int may_open_tabpage(void);
! static int win_enter_ext(win_T *wp, int flags);
  static void win_free(win_T *wp, tabpage_T *tp);
  static int win_unlisted(win_T *wp);
  static void win_append(win_T *after, win_T *wp);
***************
*** 73,78 ****
--- 73,79 ----
  #define WEE_TRIGGER_NEW_AUTOCMDS      0x04
  #define WEE_TRIGGER_ENTER_AUTOCMDS    0x08
  #define WEE_TRIGGER_LEAVE_AUTOCMDS    0x10
+ #define WEE_ALLOW_PARSE_MESSAGES      0x20
  
  static char *m_onlyone = N_("Already only one window");
  
***************
*** 1338,1345 ****
      /*
       * make the new window the current window
       */
!     win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS
!                                                | WEE_TRIGGER_LEAVE_AUTOCMDS);
      if (flags & WSP_VERT)
        p_wiw = i;
      else
--- 1339,1346 ----
      /*
       * make the new window the current window
       */
!     (void)win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS
!                   | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
      if (flags & WSP_VERT)
        p_wiw = i;
      else
***************
*** 2483,2488 ****
--- 2484,2490 ----
  #ifdef FEAT_DIFF
      int               had_diffmode = win->w_p_diff;
  #endif
+     int               did_decrement = FALSE;
  
  #if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP)
      // Can close a popup window with a terminal if the job has finished.
***************
*** 2661,2668 ****
        win_comp_pos();
      if (close_curwin)
      {
!       win_enter_ext(wp, WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS
!                                                | WEE_TRIGGER_LEAVE_AUTOCMDS);
        if (other_buffer)
            // careful: after this wp and win may be invalid!
            apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
--- 2663,2673 ----
        win_comp_pos();
      if (close_curwin)
      {
!       // Pass WEE_ALLOW_PARSE_MESSAGES to decrement dont_parse_messages
!       // before autocommands.
!       did_decrement = win_enter_ext(wp,
!               WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS
!                     | WEE_TRIGGER_LEAVE_AUTOCMDS | WEE_ALLOW_PARSE_MESSAGES);
        if (other_buffer)
            // careful: after this wp and win may be invalid!
            apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
***************
*** 2670,2676 ****
  
      --split_disallowed;
  #ifdef MESSAGE_QUEUE
!     --dont_parse_messages;
  #endif
  
      /*
--- 2675,2682 ----
  
      --split_disallowed;
  #ifdef MESSAGE_QUEUE
!     if (!did_decrement)
!       --dont_parse_messages;
  #endif
  
      /*
***************
*** 4188,4194 ****
      // We would like doing the TabEnter event first, but we don't have a
      // valid current window yet, which may break some commands.
      // This triggers autocommands, thus may make "tp" invalid.
!     win_enter_ext(tp->tp_curwin, WEE_CURWIN_INVALID
                  | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0)
                  | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0));
      prevwin = next_prevwin;
--- 4194,4200 ----
      // We would like doing the TabEnter event first, but we don't have a
      // valid current window yet, which may break some commands.
      // This triggers autocommands, thus may make "tp" invalid.
!     (void)win_enter_ext(tp->tp_curwin, WEE_CURWIN_INVALID
                  | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0)
                  | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0));
      prevwin = next_prevwin;
***************
*** 4476,4482 ****
  #endif
  }
  
! #if defined(FEAT_PERL) || defined(PROTO)
  /*
   * Find window number "winnr" (counting top to bottom).
   */
--- 4482,4488 ----
  #endif
  }
  
! #if defined(FEAT_PERL) || defined(FEAT_LUA) || defined(PROTO)
  /*
   * Find window number "winnr" (counting top to bottom).
   */
***************
*** 4689,4695 ****
      void
  win_enter(win_T *wp, int undo_sync)
  {
!     win_enter_ext(wp, (undo_sync ? WEE_UNDO_SYNC : 0)
                    | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
  }
  
--- 4695,4701 ----
      void
  win_enter(win_T *wp, int undo_sync)
  {
!     (void)win_enter_ext(wp, (undo_sync ? WEE_UNDO_SYNC : 0)
                    | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
  }
  
***************
*** 4697,4711 ****
   * Make window "wp" the current window.
   * Can be called with "flags" containing WEE_CURWIN_INVALID, which means that
   * curwin has just been closed and isn't valid.
   */
!     static void
  win_enter_ext(win_T *wp, int flags)
  {
      int               other_buffer = FALSE;
      int               curwin_invalid = (flags & WEE_CURWIN_INVALID);
  
      if (wp == curwin && !curwin_invalid)      // nothing to do
!       return;
  
  #ifdef FEAT_JOB_CHANNEL
      if (!curwin_invalid)
--- 4703,4719 ----
   * Make window "wp" the current window.
   * Can be called with "flags" containing WEE_CURWIN_INVALID, which means that
   * curwin has just been closed and isn't valid.
+  * Returns TRUE when dont_parse_messages was decremented.
   */
!     static int
  win_enter_ext(win_T *wp, int flags)
  {
      int               other_buffer = FALSE;
      int               curwin_invalid = (flags & WEE_CURWIN_INVALID);
+     int               did_decrement = FALSE;
  
      if (wp == curwin && !curwin_invalid)      // nothing to do
!       return FALSE;
  
  #ifdef FEAT_JOB_CHANNEL
      if (!curwin_invalid)
***************
*** 4722,4736 ****
            apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
            other_buffer = TRUE;
            if (!win_valid(wp))
!               return;
        }
        apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
        if (!win_valid(wp))
!           return;
  #ifdef FEAT_EVAL
        // autocmds may abort script processing
        if (aborting())
!           return;
  #endif
      }
  
--- 4730,4744 ----
            apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
            other_buffer = TRUE;
            if (!win_valid(wp))
!               return FALSE;
        }
        apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
        if (!win_valid(wp))
!           return FALSE;
  #ifdef FEAT_EVAL
        // autocmds may abort script processing
        if (aborting())
!           return FALSE;
  #endif
      }
  
***************
*** 4757,4762 ****
--- 4765,4780 ----
        curwin->w_cursor.coladd = 0;
      changed_line_abv_curs();  // assume cursor position needs updating
  
+     // Now it is OK to parse messages again, which may be needed in
+     // autocommands.
+ #ifdef MESSAGE_QUEUE
+     if (flags & WEE_ALLOW_PARSE_MESSAGES)
+     {
+       --dont_parse_messages;
+       did_decrement = TRUE;
+     }
+ #endif
+ 
      if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
      {
        char_u  *dirname;
***************
*** 4832,4837 ****
--- 4850,4857 ----
  
      // Change directories when the 'acd' option is set.
      DO_AUTOCHDIR;
+ 
+     return did_decrement;
  }
  
  
*** ../vim-8.2.3286/src/testdir/test_channel.vim        2021-07-30 
21:56:07.110143138 +0200
--- src/testdir/test_channel.vim        2021-08-04 20:53:40.870088889 +0200
***************
*** 2330,2333 ****
--- 2330,2362 ----
    unlet g:wait_exit_cb
  endfunc
  
+ function s:HandleBufEnter() abort
+   let queue = []
+   let job = job_start(['date'], {'callback': { j, d -> add(queue, d) }})
+   while empty(queue)
+     sleep! 10m
+   endwhile
+ endfunction
+ 
+ func Test_parse_messages_in_autocmd()
+   CheckUnix
+ 
+   " Check that in the BufEnter autocommand events are being handled
+   augroup bufenterjob
+     autocmd!
+     autocmd BufEnter Xbufenterjob call s:HandleBufEnter()
+   augroup END
+ 
+   only
+   split Xbufenterjob
+   wincmd p
+   redraw
+ 
+   close
+   augroup bufenterjob
+     autocmd!
+   augroup END
+ endfunc
+ 
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.3286/src/version.c       2021-08-04 20:26:16.034253844 +0200
--- src/version.c       2021-08-04 20:49:48.602798500 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3287,
  /**/

-- 
"A mouse can be just as dangerous as a bullet or a bomb."
             (US Representative Lamar Smith, R-Texas)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202108041857.174Iv0LX1110289%40masaka.moolenaar.net.

Raspunde prin e-mail lui