99b86a7
To: vim-dev@vim.org
99b86a7
Subject: patch 7.1.125
99b86a7
Fcc: outbox
99b86a7
From: Bram Moolenaar <Bram@moolenaar.net>
99b86a7
Mime-Version: 1.0
99b86a7
Content-Type: text/plain; charset=ISO-8859-1
99b86a7
Content-Transfer-Encoding: 8bit
99b86a7
------------
99b86a7
99b86a7
Patch 7.1.125
99b86a7
Problem:    The TermResponse autocommand event is not always triggered. (Aron
99b86a7
	    Griffis)
99b86a7
Solution:   When unblocking autocommands check if v:termresponse changed and
99b86a7
	    trigger the event then.
99b86a7
Files:	    src/buffer.c, src/diff.c, src/ex_getln.c, src/fileio.c,
99b86a7
	    src/globals.h, src/misc2.c, src/proto/fileio.pro, src/window.c
99b86a7
99b86a7
99b86a7
*** ../vim-7.1.124/src/buffer.c	Sun Aug 12 15:50:26 2007
99b86a7
--- src/buffer.c	Wed Sep 26 20:05:38 2007
99b86a7
***************
99b86a7
*** 5515,5525 ****
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      if (!aucmd)		    /* Don't trigger BufDelete autocommands here. */
99b86a7
! 	++autocmd_block;
99b86a7
  #endif
99b86a7
      close_buffer(NULL, buf, DOBUF_WIPE);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      if (!aucmd)
99b86a7
! 	--autocmd_block;
99b86a7
  #endif
99b86a7
  }
99b86a7
--- 5512,5522 ----
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      if (!aucmd)		    /* Don't trigger BufDelete autocommands here. */
99b86a7
! 	block_autocmds();
99b86a7
  #endif
99b86a7
      close_buffer(NULL, buf, DOBUF_WIPE);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      if (!aucmd)
99b86a7
! 	unblock_autocmds();
99b86a7
  #endif
99b86a7
  }
99b86a7
*** ../vim-7.1.124/src/diff.c	Tue Feb 20 04:43:13 2007
99b86a7
--- src/diff.c	Tue Sep 25 22:01:40 2007
99b86a7
***************
99b86a7
*** 840,850 ****
99b86a7
  		    tmp_orig, tmp_new);
99b86a7
  	    append_redir(cmd, p_srr, tmp_diff);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	    ++autocmd_block;	/* Avoid ShellCmdPost stuff */
99b86a7
  #endif
99b86a7
  	    (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	    --autocmd_block;
99b86a7
  #endif
99b86a7
  	    vim_free(cmd);
99b86a7
  	}
99b86a7
--- 840,850 ----
99b86a7
  		    tmp_orig, tmp_new);
99b86a7
  	    append_redir(cmd, p_srr, tmp_diff);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	    block_autocmds();	/* Avoid ShellCmdPost stuff */
99b86a7
  #endif
99b86a7
  	    (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	    unblock_autocmds();
99b86a7
  #endif
99b86a7
  	    vim_free(cmd);
99b86a7
  	}
99b86a7
***************
99b86a7
*** 949,959 ****
99b86a7
  # endif
99b86a7
  		eap->arg);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	++autocmd_block;	/* Avoid ShellCmdPost stuff */
99b86a7
  #endif
99b86a7
  	(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	--autocmd_block;
99b86a7
  #endif
99b86a7
      }
99b86a7
  
99b86a7
--- 949,959 ----
99b86a7
  # endif
99b86a7
  		eap->arg);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	block_autocmds();	/* Avoid ShellCmdPost stuff */
99b86a7
  #endif
99b86a7
  	(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	unblock_autocmds();
99b86a7
  #endif
99b86a7
      }
99b86a7
  
99b86a7
*** ../vim-7.1.124/src/ex_getln.c	Thu Sep 13 18:25:08 2007
99b86a7
--- src/ex_getln.c	Tue Sep 25 22:03:05 2007
99b86a7
***************
99b86a7
*** 5925,5931 ****
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
      /* Don't execute autocommands while creating the window. */
99b86a7
!     ++autocmd_block;
99b86a7
  # endif
99b86a7
      /* don't use a new tab page */
99b86a7
      cmdmod.tab = 0;
99b86a7
--- 5925,5931 ----
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
      /* Don't execute autocommands while creating the window. */
99b86a7
!     block_autocmds();
99b86a7
  # endif
99b86a7
      /* don't use a new tab page */
99b86a7
      cmdmod.tab = 0;
99b86a7
***************
99b86a7
*** 5934,5939 ****
99b86a7
--- 5934,5942 ----
99b86a7
      if (win_split((int)p_cwh, WSP_BOT) == FAIL)
99b86a7
      {
99b86a7
  	beep_flush();
99b86a7
+ # ifdef FEAT_AUTOCMD
99b86a7
+ 	unblock_autocmds();
99b86a7
+ # endif
99b86a7
  	return K_IGNORE;
99b86a7
      }
99b86a7
      cmdwin_type = ccline.cmdfirstc;
99b86a7
***************
99b86a7
*** 5956,5962 ****
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
      /* Do execute autocommands for setting the filetype (load syntax). */
99b86a7
!     --autocmd_block;
99b86a7
  # endif
99b86a7
  
99b86a7
      /* Showing the prompt may have set need_wait_return, reset it. */
99b86a7
--- 5959,5965 ----
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
      /* Do execute autocommands for setting the filetype (load syntax). */
99b86a7
!     unblock_autocmds();
99b86a7
  # endif
99b86a7
  
99b86a7
      /* Showing the prompt may have set need_wait_return, reset it. */
99b86a7
***************
99b86a7
*** 6110,6116 ****
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
  	/* Don't execute autocommands while deleting the window. */
99b86a7
! 	++autocmd_block;
99b86a7
  # endif
99b86a7
  	wp = curwin;
99b86a7
  	bp = curbuf;
99b86a7
--- 6113,6119 ----
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
  	/* Don't execute autocommands while deleting the window. */
99b86a7
! 	block_autocmds();
99b86a7
  # endif
99b86a7
  	wp = curwin;
99b86a7
  	bp = curbuf;
99b86a7
***************
99b86a7
*** 6122,6128 ****
99b86a7
  	win_size_restore(&winsizes);
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
! 	--autocmd_block;
99b86a7
  # endif
99b86a7
      }
99b86a7
  
99b86a7
--- 6125,6131 ----
99b86a7
  	win_size_restore(&winsizes);
99b86a7
  
99b86a7
  # ifdef FEAT_AUTOCMD
99b86a7
! 	unblock_autocmds();
99b86a7
  # endif
99b86a7
      }
99b86a7
  
99b86a7
*** ../vim-7.1.124/src/fileio.c	Sun Aug 12 15:50:26 2007
99b86a7
--- src/fileio.c	Wed Sep 26 20:02:54 2007
99b86a7
***************
99b86a7
*** 7165,7170 ****
99b86a7
--- 7187,7193 ----
99b86a7
  
99b86a7
  static event_T	last_event;
99b86a7
  static int	last_group;
99b86a7
+ static int	autocmd_blocked = 0;	/* block all autocmds */
99b86a7
  
99b86a7
  /*
99b86a7
   * Show the autocommands for one AutoPat.
99b86a7
***************
99b86a7
*** 8454,8460 ****
99b86a7
       * Quickly return if there are no autocommands for this event or
99b86a7
       * autocommands are blocked.
99b86a7
       */
99b86a7
!     if (first_autopat[(int)event] == NULL || autocmd_block > 0)
99b86a7
  	goto BYPASS_AU;
99b86a7
  
99b86a7
      /*
99b86a7
--- 8477,8483 ----
99b86a7
       * Quickly return if there are no autocommands for this event or
99b86a7
       * autocommands are blocked.
99b86a7
       */
99b86a7
!     if (first_autopat[(int)event] == NULL || autocmd_blocked > 0)
99b86a7
  	goto BYPASS_AU;
99b86a7
  
99b86a7
      /*
99b86a7
***************
99b86a7
*** 8766,8771 ****
99b86a7
--- 8789,8828 ----
99b86a7
  	aubuflocal_remove(buf);
99b86a7
  
99b86a7
      return retval;
99b86a7
+ }
99b86a7
+ 
99b86a7
+ # ifdef FEAT_EVAL
99b86a7
+ static char_u	*old_termresponse = NULL;
99b86a7
+ # endif
99b86a7
+ 
99b86a7
+ /*
99b86a7
+  * Block triggering autocommands until unblock_autocmd() is called.
99b86a7
+  * Can be used recursively, so long as it's symmetric.
99b86a7
+  */
99b86a7
+     void
99b86a7
+ block_autocmds()
99b86a7
+ {
99b86a7
+ # ifdef FEAT_EVAL
99b86a7
+     /* Remember the value of v:termresponse. */
99b86a7
+     if (autocmd_blocked == 0)
99b86a7
+ 	old_termresponse = get_vim_var_str(VV_TERMRESPONSE);
99b86a7
+ # endif
99b86a7
+     ++autocmd_blocked;
99b86a7
+ }
99b86a7
+ 
99b86a7
+     void
99b86a7
+ unblock_autocmds()
99b86a7
+ {
99b86a7
+     --autocmd_blocked;
99b86a7
+ 
99b86a7
+ # ifdef FEAT_EVAL
99b86a7
+     /* When v:termresponse was set while autocommands were blocked, trigger
99b86a7
+      * the autocommands now.  Esp. useful when executing a shell command
99b86a7
+      * during startup (vimdiff). */
99b86a7
+     if (autocmd_blocked == 0
99b86a7
+ 		      && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse)
99b86a7
+ 	apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf);
99b86a7
+ # endif
99b86a7
  }
99b86a7
  
99b86a7
  /*
99b86a7
*** ../vim-7.1.124/src/globals.h	Tue Sep 25 17:54:41 2007
99b86a7
--- src/globals.h	Tue Sep 25 22:03:39 2007
99b86a7
***************
99b86a7
*** 366,372 ****
99b86a7
  EXTERN int	autocmd_busy INIT(= FALSE);	/* Is apply_autocmds() busy? */
99b86a7
  EXTERN int	autocmd_no_enter INIT(= FALSE); /* *Enter autocmds disabled */
99b86a7
  EXTERN int	autocmd_no_leave INIT(= FALSE); /* *Leave autocmds disabled */
99b86a7
- EXTERN int	autocmd_block INIT(= 0);	/* block all autocmds */
99b86a7
  EXTERN int	modified_was_set;		/* did ":set modified" */
99b86a7
  EXTERN int	did_filetype INIT(= FALSE);	/* FileType event found */
99b86a7
  EXTERN int	keep_filetype INIT(= FALSE);	/* value for did_filetype when
99b86a7
--- 366,371 ----
99b86a7
*** ../vim-7.1.124/src/misc2.c	Thu May 10 19:58:47 2007
99b86a7
--- src/misc2.c	Tue Sep 25 22:04:39 2007
99b86a7
***************
99b86a7
*** 972,978 ****
99b86a7
  	return;
99b86a7
      entered = TRUE;
99b86a7
  
99b86a7
!     ++autocmd_block;	    /* don't want to trigger autocommands here */
99b86a7
  
99b86a7
  #ifdef FEAT_WINDOWS
99b86a7
      /* close all tabs and windows */
99b86a7
--- 973,979 ----
99b86a7
  	return;
99b86a7
      entered = TRUE;
99b86a7
  
99b86a7
!     block_autocmds();	    /* don't want to trigger autocommands here */
99b86a7
  
99b86a7
  #ifdef FEAT_WINDOWS
99b86a7
      /* close all tabs and windows */
99b86a7
*** ../vim-7.1.124/src/proto/fileio.pro	Thu Jun 28 21:57:08 2007
99b86a7
--- src/proto/fileio.pro	Wed Sep 26 20:05:02 2007
99b86a7
***************
99b86a7
*** 40,45 ****
99b86a7
--- 41,48 ----
99b86a7
  int trigger_cursorhold __ARGS((void));
99b86a7
  int has_cursormoved __ARGS((void));
99b86a7
  int has_cursormovedI __ARGS((void));
99b86a7
+ void block_autocmds __ARGS((void));
99b86a7
+ void unblock_autocmds __ARGS((void));
99b86a7
  int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
99b86a7
  char_u *get_augroup_name __ARGS((expand_T *xp, int idx));
99b86a7
  char_u *set_context_in_autocmd __ARGS((expand_T *xp, char_u *arg, int doautocmd));
99b86a7
*** ../vim-7.1.124/src/window.c	Tue Sep 25 14:50:19 2007
99b86a7
--- src/window.c	Tue Sep 25 22:05:45 2007
99b86a7
***************
99b86a7
*** 1291,1297 ****
99b86a7
       * Don't execute autocommands while creating the windows.  Must do that
99b86a7
       * when putting the buffers in the windows.
99b86a7
       */
99b86a7
!     ++autocmd_block;
99b86a7
  #endif
99b86a7
  
99b86a7
      /* todo is number of windows left to create */
99b86a7
--- 1291,1297 ----
99b86a7
       * Don't execute autocommands while creating the windows.  Must do that
99b86a7
       * when putting the buffers in the windows.
99b86a7
       */
99b86a7
!     block_autocmds();
99b86a7
  #endif
99b86a7
  
99b86a7
      /* todo is number of windows left to create */
99b86a7
***************
99b86a7
*** 1313,1319 ****
99b86a7
  	}
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     --autocmd_block;
99b86a7
  #endif
99b86a7
  
99b86a7
      /* return actual number of windows */
99b86a7
--- 1313,1319 ----
99b86a7
  	}
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     unblock_autocmds();
99b86a7
  #endif
99b86a7
  
99b86a7
      /* return actual number of windows */
99b86a7
***************
99b86a7
*** 3415,3421 ****
99b86a7
       * Don't execute autocommands while creating the tab pages.  Must do that
99b86a7
       * when putting the buffers in the windows.
99b86a7
       */
99b86a7
!     ++autocmd_block;
99b86a7
  #endif
99b86a7
  
99b86a7
      for (todo = count - 1; todo > 0; --todo)
99b86a7
--- 3415,3421 ----
99b86a7
       * Don't execute autocommands while creating the tab pages.  Must do that
99b86a7
       * when putting the buffers in the windows.
99b86a7
       */
99b86a7
!     block_autocmds();
99b86a7
  #endif
99b86a7
  
99b86a7
      for (todo = count - 1; todo > 0; --todo)
99b86a7
***************
99b86a7
*** 3423,3429 ****
99b86a7
  	    break;
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     --autocmd_block;
99b86a7
  #endif
99b86a7
  
99b86a7
      /* return actual number of tab pages */
99b86a7
--- 3423,3429 ----
99b86a7
  	    break;
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     unblock_autocmds();
99b86a7
  #endif
99b86a7
  
99b86a7
      /* return actual number of tab pages */
99b86a7
***************
99b86a7
*** 4162,4168 ****
99b86a7
  	/* Don't execute autocommands while the window is not properly
99b86a7
  	 * initialized yet.  gui_create_scrollbar() may trigger a FocusGained
99b86a7
  	 * event. */
99b86a7
! 	++autocmd_block;
99b86a7
  #endif
99b86a7
  	/*
99b86a7
  	 * link the window in the window list
99b86a7
--- 4162,4168 ----
99b86a7
  	/* Don't execute autocommands while the window is not properly
99b86a7
  	 * initialized yet.  gui_create_scrollbar() may trigger a FocusGained
99b86a7
  	 * event. */
99b86a7
! 	block_autocmds();
99b86a7
  #endif
99b86a7
  	/*
99b86a7
  	 * link the window in the window list
99b86a7
***************
99b86a7
*** 4207,4213 ****
99b86a7
  	foldInitWin(newwin);
99b86a7
  #endif
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	--autocmd_block;
99b86a7
  #endif
99b86a7
  #ifdef FEAT_SEARCH_EXTRA
99b86a7
  	newwin->w_match_head = NULL;
99b86a7
--- 4207,4213 ----
99b86a7
  	foldInitWin(newwin);
99b86a7
  #endif
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
! 	unblock_autocmds();
99b86a7
  #endif
99b86a7
  #ifdef FEAT_SEARCH_EXTRA
99b86a7
  	newwin->w_match_head = NULL;
99b86a7
***************
99b86a7
*** 4232,4238 ****
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      /* Don't execute autocommands while the window is halfway being deleted.
99b86a7
       * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
99b86a7
!     ++autocmd_block;
99b86a7
  #endif
99b86a7
  
99b86a7
  #ifdef FEAT_MZSCHEME
99b86a7
--- 4232,4238 ----
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
      /* Don't execute autocommands while the window is halfway being deleted.
99b86a7
       * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
99b86a7
!     block_autocmds();
99b86a7
  #endif
99b86a7
  
99b86a7
  #ifdef FEAT_MZSCHEME
99b86a7
***************
99b86a7
*** 4295,4301 ****
99b86a7
      vim_free(wp);
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     --autocmd_block;
99b86a7
  #endif
99b86a7
  }
99b86a7
  
99b86a7
--- 4295,4301 ----
99b86a7
      vim_free(wp);
99b86a7
  
99b86a7
  #ifdef FEAT_AUTOCMD
99b86a7
!     unblock_autocmds();
99b86a7
  #endif
99b86a7
  }
99b86a7
  
99b86a7
*** ../vim-7.1.124/src/version.c	Sat Sep 29 13:15:29 2007
99b86a7
--- src/version.c	Sat Sep 29 14:08:31 2007
99b86a7
***************
99b86a7
*** 668,669 ****
99b86a7
--- 668,671 ----
99b86a7
  {   /* Add new patch number below this line */
99b86a7
+ /**/
99b86a7
+     125,
99b86a7
  /**/
99b86a7
99b86a7
-- 
99b86a7
MICHAEL PALIN PLAYED: 1ST SOLDIER WITH A KEEN INTEREST IN BIRDS, DENNIS, MR
99b86a7
                      DUCK (A VILLAGE CARPENTER WHO IS ALMOST KEENER THAN
99b86a7
                      ANYONE ELSE TO BURN WITCHES), THREE-HEADED KNIGHT, SIR
99b86a7
                      GALAHAD, KING OF SWAMP CASTLE, BROTHER MAYNARD'S ROOMATE
99b86a7
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
99b86a7
99b86a7
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
99b86a7
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
99b86a7
\\\        download, build and distribute -- http://www.A-A-P.org        ///
99b86a7
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///