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