81c2858
To: vim-dev@vim.org
81c2858
Subject: Patch 7.2.241
81c2858
Fcc: outbox
81c2858
From: Bram Moolenaar <Bram@moolenaar.net>
81c2858
Mime-Version: 1.0
81c2858
Content-Type: text/plain; charset=UTF-8
81c2858
Content-Transfer-Encoding: 8bit
81c2858
------------
81c2858
81c2858
Patch 7.2.241
81c2858
Problem:    When using a combination of ":bufdo" and "doautoall" we may end up
81c2858
	    in the wrong directory. (Ajit Thakkar)
81c2858
	    Crash when triggering an autocommand in ":vimgrep".  (Yukihiro
81c2858
	    Nakadaira)
81c2858
Solution:   Clear w_localdir and globaldir when using the aucmd_win.
81c2858
	    Use a separate flag to decide aucmd_win needs to be restored.
81c2858
Files:	    src/fileio.c, src/globals.h, src/structs.h
81c2858
81c2858
81c2858
*** ../vim-7.2.240/src/fileio.c	2009-07-01 17:11:40.000000000 +0200
81c2858
--- src/fileio.c	2009-07-22 19:08:55.000000000 +0200
81c2858
***************
81c2858
*** 8420,8425 ****
81c2858
--- 8420,8429 ----
81c2858
  	if (aucmd_win == NULL)
81c2858
  	    win = curwin;
81c2858
      }
81c2858
+     if (win == NULL && aucmd_win_used)
81c2858
+ 	/* Strange recursive autocommand, fall back to using the current
81c2858
+ 	 * window.  Expect a few side effects... */
81c2858
+ 	win = curwin;
81c2858
  
81c2858
      aco->save_curwin = curwin;
81c2858
      aco->save_curbuf = curbuf;
81c2858
***************
81c2858
*** 8428,8433 ****
81c2858
--- 8432,8438 ----
81c2858
  	/* There is a window for "buf" in the current tab page, make it the
81c2858
  	 * curwin.  This is preferred, it has the least side effects (esp. if
81c2858
  	 * "buf" is curbuf). */
81c2858
+ 	aco->use_aucmd_win = FALSE;
81c2858
  	curwin = win;
81c2858
      }
81c2858
      else
81c2858
***************
81c2858
*** 8436,8444 ****
81c2858
--- 8441,8460 ----
81c2858
  	 * effects, insert it in a the current tab page.
81c2858
  	 * Anything related to a window (e.g., setting folds) may have
81c2858
  	 * unexpected results. */
81c2858
+ 	aco->use_aucmd_win = TRUE;
81c2858
+ 	aucmd_win_used = TRUE;
81c2858
  	aucmd_win->w_buffer = buf;
81c2858
  	++buf->b_nwindows;
81c2858
  	win_init_empty(aucmd_win); /* set cursor and topline to safe values */
81c2858
+ 	vim_free(aucmd_win->w_localdir);
81c2858
+ 	aucmd_win->w_localdir = NULL;
81c2858
+ 
81c2858
+ 	/* Make sure w_localdir and globaldir are NULL to avoid a chdir() in
81c2858
+ 	 * win_enter_ext(). */
81c2858
+ 	aucmd_win->w_localdir = NULL;
81c2858
+ 	aco->globaldir = globaldir;
81c2858
+ 	globaldir = NULL;
81c2858
+ 
81c2858
  
81c2858
  #ifdef FEAT_WINDOWS
81c2858
  	/* Split the current window, put the aucmd_win in the upper half.
81c2858
***************
81c2858
*** 8472,8478 ****
81c2858
      int dummy;
81c2858
  #endif
81c2858
  
81c2858
!     if (aco->new_curwin == aucmd_win)
81c2858
      {
81c2858
  	--curbuf->b_nwindows;
81c2858
  #ifdef FEAT_WINDOWS
81c2858
--- 8488,8494 ----
81c2858
      int dummy;
81c2858
  #endif
81c2858
  
81c2858
!     if (aco->use_aucmd_win)
81c2858
      {
81c2858
  	--curbuf->b_nwindows;
81c2858
  #ifdef FEAT_WINDOWS
81c2858
***************
81c2858
*** 8499,8504 ****
81c2858
--- 8515,8521 ----
81c2858
  	/* Remove the window and frame from the tree of frames. */
81c2858
  	(void)winframe_remove(curwin, &dummy, NULL);
81c2858
  	win_remove(curwin, NULL);
81c2858
+ 	aucmd_win_used = FALSE;
81c2858
  	last_status(FALSE);	    /* may need to remove last status line */
81c2858
  	restore_snapshot(SNAP_AUCMD_IDX, FALSE);
81c2858
  	(void)win_comp_pos();   /* recompute window positions */
81c2858
***************
81c2858
*** 8517,8522 ****
81c2858
--- 8534,8542 ----
81c2858
  #endif
81c2858
  	curbuf = curwin->w_buffer;
81c2858
  
81c2858
+ 	vim_free(globaldir);
81c2858
+ 	globaldir = aco->globaldir;
81c2858
+ 
81c2858
  	/* the buffer contents may have changed */
81c2858
  	check_cursor();
81c2858
  	if (curwin->w_topline > curbuf->b_ml.ml_line_count)
81c2858
***************
81c2858
*** 8541,8547 ****
81c2858
  #endif
81c2858
  	{
81c2858
  	    /* Restore the buffer which was previously edited by curwin, if
81c2858
! 	     * it was chagned, we are still the same window and the buffer is
81c2858
  	     * valid. */
81c2858
  	    if (curwin == aco->new_curwin
81c2858
  		    && curbuf != aco->new_curbuf
81c2858
--- 8561,8567 ----
81c2858
  #endif
81c2858
  	{
81c2858
  	    /* Restore the buffer which was previously edited by curwin, if
81c2858
! 	     * it was changed, we are still the same window and the buffer is
81c2858
  	     * valid. */
81c2858
  	    if (curwin == aco->new_curwin
81c2858
  		    && curbuf != aco->new_curbuf
81c2858
*** ../vim-7.2.240/src/globals.h	2009-06-16 16:01:34.000000000 +0200
81c2858
--- src/globals.h	2009-07-22 19:50:53.000000000 +0200
81c2858
***************
81c2858
*** 541,546 ****
81c2858
--- 541,547 ----
81c2858
  
81c2858
  #ifdef FEAT_AUTOCMD
81c2858
  EXTERN win_T	*aucmd_win;	/* window used in aucmd_prepbuf() */
81c2858
+ EXTERN int	aucmd_win_used INIT(= FALSE);	/* aucmd_win is being used */
81c2858
  #endif
81c2858
  
81c2858
  /*
81c2858
*** ../vim-7.2.240/src/structs.h	2009-07-09 18:24:24.000000000 +0200
81c2858
--- src/structs.h	2009-07-22 18:58:35.000000000 +0200
81c2858
***************
81c2858
*** 2288,2296 ****
81c2858
--- 2288,2298 ----
81c2858
  {
81c2858
      buf_T	*save_curbuf;	/* saved curbuf */
81c2858
  #ifdef FEAT_AUTOCMD
81c2858
+     int		use_aucmd_win;	/* using aucmd_win */
81c2858
      win_T	*save_curwin;	/* saved curwin */
81c2858
      win_T	*new_curwin;	/* new curwin */
81c2858
      buf_T	*new_curbuf;	/* new curbuf */
81c2858
+     char_u	*globaldir;	/* saved value of globaldir */
81c2858
  #endif
81c2858
  } aco_save_T;
81c2858
  
81c2858
*** ../vim-7.2.240/src/version.c	2009-07-29 11:10:31.000000000 +0200
81c2858
--- src/version.c	2009-07-29 12:06:31.000000000 +0200
81c2858
***************
81c2858
*** 678,679 ****
81c2858
--- 678,681 ----
81c2858
  {   /* Add new patch number below this line */
81c2858
+ /**/
81c2858
+     241,
81c2858
  /**/
81c2858
81c2858
-- 
81c2858
hundred-and-one symptoms of being an internet addict:
81c2858
114. You are counting items, you go "0,1,2,3,4,5,6,7,8,9,A,B,C,D...".
81c2858
81c2858
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
81c2858
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
81c2858
\\\        download, build and distribute -- http://www.A-A-P.org        ///
81c2858
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///