Blob Blame History Raw
To: vim-dev@vim.org
Subject: patch 7.1.125
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.1.125
Problem:    The TermResponse autocommand event is not always triggered. (Aron
	    Griffis)
Solution:   When unblocking autocommands check if v:termresponse changed and
	    trigger the event then.
Files:	    src/buffer.c, src/diff.c, src/ex_getln.c, src/fileio.c,
	    src/globals.h, src/misc2.c, src/proto/fileio.pro, src/window.c


*** ../vim-7.1.124/src/buffer.c	Sun Aug 12 15:50:26 2007
--- src/buffer.c	Wed Sep 26 20:05:38 2007
***************
*** 5515,5525 ****
  
  #ifdef FEAT_AUTOCMD
      if (!aucmd)		    /* Don't trigger BufDelete autocommands here. */
! 	++autocmd_block;
  #endif
      close_buffer(NULL, buf, DOBUF_WIPE);
  #ifdef FEAT_AUTOCMD
      if (!aucmd)
! 	--autocmd_block;
  #endif
  }
--- 5512,5522 ----
  
  #ifdef FEAT_AUTOCMD
      if (!aucmd)		    /* Don't trigger BufDelete autocommands here. */
! 	block_autocmds();
  #endif
      close_buffer(NULL, buf, DOBUF_WIPE);
  #ifdef FEAT_AUTOCMD
      if (!aucmd)
! 	unblock_autocmds();
  #endif
  }
*** ../vim-7.1.124/src/diff.c	Tue Feb 20 04:43:13 2007
--- src/diff.c	Tue Sep 25 22:01:40 2007
***************
*** 840,850 ****
  		    tmp_orig, tmp_new);
  	    append_redir(cmd, p_srr, tmp_diff);
  #ifdef FEAT_AUTOCMD
! 	    ++autocmd_block;	/* Avoid ShellCmdPost stuff */
  #endif
  	    (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
  #ifdef FEAT_AUTOCMD
! 	    --autocmd_block;
  #endif
  	    vim_free(cmd);
  	}
--- 840,850 ----
  		    tmp_orig, tmp_new);
  	    append_redir(cmd, p_srr, tmp_diff);
  #ifdef FEAT_AUTOCMD
! 	    block_autocmds();	/* Avoid ShellCmdPost stuff */
  #endif
  	    (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
  #ifdef FEAT_AUTOCMD
! 	    unblock_autocmds();
  #endif
  	    vim_free(cmd);
  	}
***************
*** 949,959 ****
  # endif
  		eap->arg);
  #ifdef FEAT_AUTOCMD
! 	++autocmd_block;	/* Avoid ShellCmdPost stuff */
  #endif
  	(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
  #ifdef FEAT_AUTOCMD
! 	--autocmd_block;
  #endif
      }
  
--- 949,959 ----
  # endif
  		eap->arg);
  #ifdef FEAT_AUTOCMD
! 	block_autocmds();	/* Avoid ShellCmdPost stuff */
  #endif
  	(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
  #ifdef FEAT_AUTOCMD
! 	unblock_autocmds();
  #endif
      }
  
*** ../vim-7.1.124/src/ex_getln.c	Thu Sep 13 18:25:08 2007
--- src/ex_getln.c	Tue Sep 25 22:03:05 2007
***************
*** 5925,5931 ****
  
  # ifdef FEAT_AUTOCMD
      /* Don't execute autocommands while creating the window. */
!     ++autocmd_block;
  # endif
      /* don't use a new tab page */
      cmdmod.tab = 0;
--- 5925,5931 ----
  
  # ifdef FEAT_AUTOCMD
      /* Don't execute autocommands while creating the window. */
!     block_autocmds();
  # endif
      /* don't use a new tab page */
      cmdmod.tab = 0;
***************
*** 5934,5939 ****
--- 5934,5942 ----
      if (win_split((int)p_cwh, WSP_BOT) == FAIL)
      {
  	beep_flush();
+ # ifdef FEAT_AUTOCMD
+ 	unblock_autocmds();
+ # endif
  	return K_IGNORE;
      }
      cmdwin_type = ccline.cmdfirstc;
***************
*** 5956,5962 ****
  
  # ifdef FEAT_AUTOCMD
      /* Do execute autocommands for setting the filetype (load syntax). */
!     --autocmd_block;
  # endif
  
      /* Showing the prompt may have set need_wait_return, reset it. */
--- 5959,5965 ----
  
  # ifdef FEAT_AUTOCMD
      /* Do execute autocommands for setting the filetype (load syntax). */
!     unblock_autocmds();
  # endif
  
      /* Showing the prompt may have set need_wait_return, reset it. */
***************
*** 6110,6116 ****
  
  # ifdef FEAT_AUTOCMD
  	/* Don't execute autocommands while deleting the window. */
! 	++autocmd_block;
  # endif
  	wp = curwin;
  	bp = curbuf;
--- 6113,6119 ----
  
  # ifdef FEAT_AUTOCMD
  	/* Don't execute autocommands while deleting the window. */
! 	block_autocmds();
  # endif
  	wp = curwin;
  	bp = curbuf;
***************
*** 6122,6128 ****
  	win_size_restore(&winsizes);
  
  # ifdef FEAT_AUTOCMD
! 	--autocmd_block;
  # endif
      }
  
--- 6125,6131 ----
  	win_size_restore(&winsizes);
  
  # ifdef FEAT_AUTOCMD
! 	unblock_autocmds();
  # endif
      }
  
*** ../vim-7.1.124/src/fileio.c	Sun Aug 12 15:50:26 2007
--- src/fileio.c	Wed Sep 26 20:02:54 2007
***************
*** 7165,7170 ****
--- 7187,7193 ----
  
  static event_T	last_event;
  static int	last_group;
+ static int	autocmd_blocked = 0;	/* block all autocmds */
  
  /*
   * Show the autocommands for one AutoPat.
***************
*** 8454,8460 ****
       * Quickly return if there are no autocommands for this event or
       * autocommands are blocked.
       */
!     if (first_autopat[(int)event] == NULL || autocmd_block > 0)
  	goto BYPASS_AU;
  
      /*
--- 8477,8483 ----
       * Quickly return if there are no autocommands for this event or
       * autocommands are blocked.
       */
!     if (first_autopat[(int)event] == NULL || autocmd_blocked > 0)
  	goto BYPASS_AU;
  
      /*
***************
*** 8766,8771 ****
--- 8789,8828 ----
  	aubuflocal_remove(buf);
  
      return retval;
+ }
+ 
+ # ifdef FEAT_EVAL
+ static char_u	*old_termresponse = NULL;
+ # endif
+ 
+ /*
+  * Block triggering autocommands until unblock_autocmd() is called.
+  * Can be used recursively, so long as it's symmetric.
+  */
+     void
+ block_autocmds()
+ {
+ # ifdef FEAT_EVAL
+     /* Remember the value of v:termresponse. */
+     if (autocmd_blocked == 0)
+ 	old_termresponse = get_vim_var_str(VV_TERMRESPONSE);
+ # endif
+     ++autocmd_blocked;
+ }
+ 
+     void
+ unblock_autocmds()
+ {
+     --autocmd_blocked;
+ 
+ # ifdef FEAT_EVAL
+     /* When v:termresponse was set while autocommands were blocked, trigger
+      * the autocommands now.  Esp. useful when executing a shell command
+      * during startup (vimdiff). */
+     if (autocmd_blocked == 0
+ 		      && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse)
+ 	apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf);
+ # endif
  }
  
  /*
*** ../vim-7.1.124/src/globals.h	Tue Sep 25 17:54:41 2007
--- src/globals.h	Tue Sep 25 22:03:39 2007
***************
*** 366,372 ****
  EXTERN int	autocmd_busy INIT(= FALSE);	/* Is apply_autocmds() busy? */
  EXTERN int	autocmd_no_enter INIT(= FALSE); /* *Enter autocmds disabled */
  EXTERN int	autocmd_no_leave INIT(= FALSE); /* *Leave autocmds disabled */
- EXTERN int	autocmd_block INIT(= 0);	/* block all autocmds */
  EXTERN int	modified_was_set;		/* did ":set modified" */
  EXTERN int	did_filetype INIT(= FALSE);	/* FileType event found */
  EXTERN int	keep_filetype INIT(= FALSE);	/* value for did_filetype when
--- 366,371 ----
*** ../vim-7.1.124/src/misc2.c	Thu May 10 19:58:47 2007
--- src/misc2.c	Tue Sep 25 22:04:39 2007
***************
*** 972,978 ****
  	return;
      entered = TRUE;
  
!     ++autocmd_block;	    /* don't want to trigger autocommands here */
  
  #ifdef FEAT_WINDOWS
      /* close all tabs and windows */
--- 973,979 ----
  	return;
      entered = TRUE;
  
!     block_autocmds();	    /* don't want to trigger autocommands here */
  
  #ifdef FEAT_WINDOWS
      /* close all tabs and windows */
*** ../vim-7.1.124/src/proto/fileio.pro	Thu Jun 28 21:57:08 2007
--- src/proto/fileio.pro	Wed Sep 26 20:05:02 2007
***************
*** 40,45 ****
--- 41,48 ----
  int trigger_cursorhold __ARGS((void));
  int has_cursormoved __ARGS((void));
  int has_cursormovedI __ARGS((void));
+ void block_autocmds __ARGS((void));
+ void unblock_autocmds __ARGS((void));
  int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
  char_u *get_augroup_name __ARGS((expand_T *xp, int idx));
  char_u *set_context_in_autocmd __ARGS((expand_T *xp, char_u *arg, int doautocmd));
*** ../vim-7.1.124/src/window.c	Tue Sep 25 14:50:19 2007
--- src/window.c	Tue Sep 25 22:05:45 2007
***************
*** 1291,1297 ****
       * Don't execute autocommands while creating the windows.  Must do that
       * when putting the buffers in the windows.
       */
!     ++autocmd_block;
  #endif
  
      /* todo is number of windows left to create */
--- 1291,1297 ----
       * Don't execute autocommands while creating the windows.  Must do that
       * when putting the buffers in the windows.
       */
!     block_autocmds();
  #endif
  
      /* todo is number of windows left to create */
***************
*** 1313,1319 ****
  	}
  
  #ifdef FEAT_AUTOCMD
!     --autocmd_block;
  #endif
  
      /* return actual number of windows */
--- 1313,1319 ----
  	}
  
  #ifdef FEAT_AUTOCMD
!     unblock_autocmds();
  #endif
  
      /* return actual number of windows */
***************
*** 3415,3421 ****
       * Don't execute autocommands while creating the tab pages.  Must do that
       * when putting the buffers in the windows.
       */
!     ++autocmd_block;
  #endif
  
      for (todo = count - 1; todo > 0; --todo)
--- 3415,3421 ----
       * Don't execute autocommands while creating the tab pages.  Must do that
       * when putting the buffers in the windows.
       */
!     block_autocmds();
  #endif
  
      for (todo = count - 1; todo > 0; --todo)
***************
*** 3423,3429 ****
  	    break;
  
  #ifdef FEAT_AUTOCMD
!     --autocmd_block;
  #endif
  
      /* return actual number of tab pages */
--- 3423,3429 ----
  	    break;
  
  #ifdef FEAT_AUTOCMD
!     unblock_autocmds();
  #endif
  
      /* return actual number of tab pages */
***************
*** 4162,4168 ****
  	/* Don't execute autocommands while the window is not properly
  	 * initialized yet.  gui_create_scrollbar() may trigger a FocusGained
  	 * event. */
! 	++autocmd_block;
  #endif
  	/*
  	 * link the window in the window list
--- 4162,4168 ----
  	/* Don't execute autocommands while the window is not properly
  	 * initialized yet.  gui_create_scrollbar() may trigger a FocusGained
  	 * event. */
! 	block_autocmds();
  #endif
  	/*
  	 * link the window in the window list
***************
*** 4207,4213 ****
  	foldInitWin(newwin);
  #endif
  #ifdef FEAT_AUTOCMD
! 	--autocmd_block;
  #endif
  #ifdef FEAT_SEARCH_EXTRA
  	newwin->w_match_head = NULL;
--- 4207,4213 ----
  	foldInitWin(newwin);
  #endif
  #ifdef FEAT_AUTOCMD
! 	unblock_autocmds();
  #endif
  #ifdef FEAT_SEARCH_EXTRA
  	newwin->w_match_head = NULL;
***************
*** 4232,4238 ****
  #ifdef FEAT_AUTOCMD
      /* Don't execute autocommands while the window is halfway being deleted.
       * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
!     ++autocmd_block;
  #endif
  
  #ifdef FEAT_MZSCHEME
--- 4232,4238 ----
  #ifdef FEAT_AUTOCMD
      /* Don't execute autocommands while the window is halfway being deleted.
       * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */
!     block_autocmds();
  #endif
  
  #ifdef FEAT_MZSCHEME
***************
*** 4295,4301 ****
      vim_free(wp);
  
  #ifdef FEAT_AUTOCMD
!     --autocmd_block;
  #endif
  }
  
--- 4295,4301 ----
      vim_free(wp);
  
  #ifdef FEAT_AUTOCMD
!     unblock_autocmds();
  #endif
  }
  
*** ../vim-7.1.124/src/version.c	Sat Sep 29 13:15:29 2007
--- src/version.c	Sat Sep 29 14:08:31 2007
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     125,
  /**/

-- 
MICHAEL PALIN PLAYED: 1ST SOLDIER WITH A KEEN INTEREST IN BIRDS, DENNIS, MR
                      DUCK (A VILLAGE CARPENTER WHO IS ALMOST KEENER THAN
                      ANYONE ELSE TO BURN WITCHES), THREE-HEADED KNIGHT, SIR
                      GALAHAD, KING OF SWAMP CASTLE, BROTHER MAYNARD'S ROOMATE
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///