Karsten Hopp 65512b
To: vim-dev@vim.org
Karsten Hopp 65512b
Subject: patch 7.1.126
Karsten Hopp 65512b
Fcc: outbox
Karsten Hopp 65512b
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 65512b
Mime-Version: 1.0
Karsten Hopp 65512b
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 65512b
Content-Transfer-Encoding: 8bit
Karsten Hopp 65512b
------------
Karsten Hopp 65512b
Karsten Hopp 65512b
Patch 7.1.126
Karsten Hopp 65512b
Problem:    ":vimgrep */*" fails when a BufRead autocommand changes directory.
Karsten Hopp 65512b
	    (Bernhard Kuhn)
Karsten Hopp 65512b
Solution:   Change back to the original directory after loading a file.
Karsten Hopp 65512b
	    Also: use shorten_fname1() to avoid duplicating code.
Karsten Hopp 65512b
Files:	    src/buffer.c, src/ex_docmd.c, src/fileio.c, src/gui_gtk.c,
Karsten Hopp 65512b
	    src/gui_w48.c, src/proto/ex_docmd.pro, src/proto/fileio.pro,
Karsten Hopp 65512b
	    src/quickfix.c
Karsten Hopp 65512b
Karsten Hopp 65512b
Karsten Hopp 65512b
*** ../vim-7.1.125/src/buffer.c	Sat Sep 29 14:15:00 2007
Karsten Hopp 65512b
--- src/buffer.c	Wed Sep 26 20:05:38 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 4261,4272 ****
Karsten Hopp 65512b
  do_arg_all(count, forceit, keep_tabs)
Karsten Hopp 65512b
      int	count;
Karsten Hopp 65512b
      int	forceit;		/* hide buffers in current windows */
Karsten Hopp 65512b
!     int keep_tabs;		/* keep curren tabs, for ":tab drop file" */
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
      int		i;
Karsten Hopp 65512b
      win_T	*wp, *wpnext;
Karsten Hopp 65512b
      char_u	*opened;	/* array of flags for which args are open */
Karsten Hopp 65512b
!     int		opened_len;	/* lenght of opened[] */
Karsten Hopp 65512b
      int		use_firstwin = FALSE;	/* use first window for arglist */
Karsten Hopp 65512b
      int		split_ret = OK;
Karsten Hopp 65512b
      int		p_ea_save;
Karsten Hopp 65512b
--- 4261,4272 ----
Karsten Hopp 65512b
  do_arg_all(count, forceit, keep_tabs)
Karsten Hopp 65512b
      int	count;
Karsten Hopp 65512b
      int	forceit;		/* hide buffers in current windows */
Karsten Hopp 65512b
!     int keep_tabs;		/* keep current tabs, for ":tab drop file" */
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
      int		i;
Karsten Hopp 65512b
      win_T	*wp, *wpnext;
Karsten Hopp 65512b
      char_u	*opened;	/* array of flags for which args are open */
Karsten Hopp 65512b
!     int		opened_len;	/* length of opened[] */
Karsten Hopp 65512b
      int		use_firstwin = FALSE;	/* use first window for arglist */
Karsten Hopp 65512b
      int		split_ret = OK;
Karsten Hopp 65512b
      int		p_ea_save;
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 4946,4955 ****
Karsten Hopp 65512b
  	/* Expand "~/" in the file name at "line + 1" to a full path.
Karsten Hopp 65512b
  	 * Then try shortening it by comparing with the current directory */
Karsten Hopp 65512b
  	expand_env(xline, NameBuff, MAXPATHL);
Karsten Hopp 65512b
! 	mch_dirname(IObuff, IOSIZE);
Karsten Hopp 65512b
! 	sfname = shorten_fname(NameBuff, IObuff);
Karsten Hopp 65512b
! 	if (sfname == NULL)
Karsten Hopp 65512b
! 	    sfname = NameBuff;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
Karsten Hopp 65512b
  	if (buf != NULL)	/* just in case... */
Karsten Hopp 65512b
--- 4946,4952 ----
Karsten Hopp 65512b
  	/* Expand "~/" in the file name at "line + 1" to a full path.
Karsten Hopp 65512b
  	 * Then try shortening it by comparing with the current directory */
Karsten Hopp 65512b
  	expand_env(xline, NameBuff, MAXPATHL);
Karsten Hopp 65512b
! 	sfname = shorten_fname1(NameBuff);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
Karsten Hopp 65512b
  	if (buf != NULL)	/* just in case... */
Karsten Hopp 65512b
*** ../vim-7.1.125/src/ex_docmd.c	Wed Sep 26 22:35:06 2007
Karsten Hopp 65512b
--- src/ex_docmd.c	Wed Sep 26 20:29:36 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 276,282 ****
Karsten Hopp 65512b
  static void	ex_swapname __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  static void	ex_syncbind __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  static void	ex_read __ARGS((exarg_T *eap));
Karsten Hopp 65512b
- static void	ex_cd __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  static void	ex_pwd __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  static void	ex_equal __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  static void	ex_sleep __ARGS((exarg_T *eap));
Karsten Hopp 65512b
--- 276,281 ----
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 7778,7784 ****
Karsten Hopp 65512b
  /*
Karsten Hopp 65512b
   * ":cd", ":lcd", ":chdir" and ":lchdir".
Karsten Hopp 65512b
   */
Karsten Hopp 65512b
!     static void
Karsten Hopp 65512b
  ex_cd(eap)
Karsten Hopp 65512b
      exarg_T	*eap;
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
--- 7777,7783 ----
Karsten Hopp 65512b
  /*
Karsten Hopp 65512b
   * ":cd", ":lcd", ":chdir" and ":lchdir".
Karsten Hopp 65512b
   */
Karsten Hopp 65512b
!     void
Karsten Hopp 65512b
  ex_cd(eap)
Karsten Hopp 65512b
      exarg_T	*eap;
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
*** ../vim-7.1.125/src/fileio.c	Sat Sep 29 14:15:00 2007
Karsten Hopp 65512b
--- src/fileio.c	Wed Sep 26 20:02:54 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 114,120 ****
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
      int		bw_fd;		/* file descriptor */
Karsten Hopp 65512b
      char_u	*bw_buf;	/* buffer with data to be written */
Karsten Hopp 65512b
!     int		bw_len;	/* lenght of data */
Karsten Hopp 65512b
  #ifdef HAS_BW_FLAGS
Karsten Hopp 65512b
      int		bw_flags;	/* FIO_ flags */
Karsten Hopp 65512b
  #endif
Karsten Hopp 65512b
--- 114,120 ----
Karsten Hopp 65512b
  {
Karsten Hopp 65512b
      int		bw_fd;		/* file descriptor */
Karsten Hopp 65512b
      char_u	*bw_buf;	/* buffer with data to be written */
Karsten Hopp 65512b
!     int		bw_len;		/* length of data */
Karsten Hopp 65512b
  #ifdef HAS_BW_FLAGS
Karsten Hopp 65512b
      int		bw_flags;	/* FIO_ flags */
Karsten Hopp 65512b
  #endif
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 5552,5557 ****
Karsten Hopp 65512b
--- 5553,5579 ----
Karsten Hopp 65512b
      return (int)(p - buf);
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  #endif
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
+ /*
Karsten Hopp 65512b
+  * Try to find a shortname by comparing the fullname with the current
Karsten Hopp 65512b
+  * directory.
Karsten Hopp 65512b
+  * Returns "full_path" or pointer into "full_path" if shortened.
Karsten Hopp 65512b
+  */
Karsten Hopp 65512b
+     char_u *
Karsten Hopp 65512b
+ shorten_fname1(full_path)
Karsten Hopp 65512b
+     char_u	*full_path;
Karsten Hopp 65512b
+ {
Karsten Hopp 65512b
+     char_u	dirname[MAXPATHL];
Karsten Hopp 65512b
+     char_u	*p = full_path;
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
+     if (mch_dirname(dirname, MAXPATHL) == OK)
Karsten Hopp 65512b
+     {
Karsten Hopp 65512b
+ 	p = shorten_fname(full_path, dirname);
Karsten Hopp 65512b
+ 	if (p == NULL || *p == NUL)
Karsten Hopp 65512b
+ 	    p = full_path;
Karsten Hopp 65512b
+     }
Karsten Hopp 65512b
+     return p;
Karsten Hopp 65512b
+ }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  /*
Karsten Hopp 65512b
   * Try to find a shortname by comparing the fullname with the current
Karsten Hopp 65512b
*** ../vim-7.1.125/src/gui_gtk.c	Tue Aug 14 14:59:41 2007
Karsten Hopp 65512b
--- src/gui_gtk.c	Wed Sep 26 20:07:58 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 1272,1278 ****
Karsten Hopp 65512b
      GtkWidget		*fc;
Karsten Hopp 65512b
  #endif
Karsten Hopp 65512b
      char_u		dirbuf[MAXPATHL];
Karsten Hopp 65512b
-     char_u		*p;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  # ifdef HAVE_GTK2
Karsten Hopp 65512b
      title = CONVERT_TO_UTF8(title);
Karsten Hopp 65512b
--- 1272,1277 ----
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 1363,1373 ****
Karsten Hopp 65512b
  	return NULL;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* shorten the file name if possible */
Karsten Hopp 65512b
!     mch_dirname(dirbuf, MAXPATHL);
Karsten Hopp 65512b
!     p = shorten_fname(gui.browse_fname, dirbuf);
Karsten Hopp 65512b
!     if (p == NULL)
Karsten Hopp 65512b
! 	p = gui.browse_fname;
Karsten Hopp 65512b
!     return vim_strsave(p);
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  #if defined(HAVE_GTK2) || defined(PROTO)
Karsten Hopp 65512b
--- 1362,1368 ----
Karsten Hopp 65512b
  	return NULL;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* shorten the file name if possible */
Karsten Hopp 65512b
!     return vim_strsave(shorten_fname1(gui.browse_fname));
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  #if defined(HAVE_GTK2) || defined(PROTO)
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 1427,1437 ****
Karsten Hopp 65512b
  	return NULL;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* shorten the file name if possible */
Karsten Hopp 65512b
!     mch_dirname(dirbuf, MAXPATHL);
Karsten Hopp 65512b
!     p = shorten_fname(dirname, dirbuf);
Karsten Hopp 65512b
!     if (p == NULL || *p == NUL)
Karsten Hopp 65512b
! 	p = dirname;
Karsten Hopp 65512b
!     p = vim_strsave(p);
Karsten Hopp 65512b
      g_free(dirname);
Karsten Hopp 65512b
      return p;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
--- 1422,1428 ----
Karsten Hopp 65512b
  	return NULL;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* shorten the file name if possible */
Karsten Hopp 65512b
!     p = vim_strsave(shorten_fname1(dirname));
Karsten Hopp 65512b
      g_free(dirname);
Karsten Hopp 65512b
      return p;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
*** ../vim-7.1.125/src/gui_w48.c	Thu May 10 19:17:07 2007
Karsten Hopp 65512b
--- src/gui_w48.c	Wed Sep 26 20:09:33 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3301,3311 ****
Karsten Hopp 65512b
      SetFocus(s_hwnd);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* Shorten the file name if possible */
Karsten Hopp 65512b
!     mch_dirname(IObuff, IOSIZE);
Karsten Hopp 65512b
!     p = shorten_fname((char_u *)fileBuf, IObuff);
Karsten Hopp 65512b
!     if (p == NULL)
Karsten Hopp 65512b
! 	p = (char_u *)fileBuf;
Karsten Hopp 65512b
!     return vim_strsave(p);
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  # endif /* FEAT_MBYTE */
Karsten Hopp 65512b
  
Karsten Hopp 65512b
--- 3301,3307 ----
Karsten Hopp 65512b
      SetFocus(s_hwnd);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* Shorten the file name if possible */
Karsten Hopp 65512b
!     return vim_strsave(shorten_fname1((char_u *)fileBuf));
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  # endif /* FEAT_MBYTE */
Karsten Hopp 65512b
  
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3450,3460 ****
Karsten Hopp 65512b
      SetFocus(s_hwnd);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* Shorten the file name if possible */
Karsten Hopp 65512b
!     mch_dirname(IObuff, IOSIZE);
Karsten Hopp 65512b
!     p = shorten_fname((char_u *)fileBuf, IObuff);
Karsten Hopp 65512b
!     if (p == NULL)
Karsten Hopp 65512b
! 	p = (char_u *)fileBuf;
Karsten Hopp 65512b
!     return vim_strsave(p);
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  #endif /* FEAT_BROWSE */
Karsten Hopp 65512b
  
Karsten Hopp 65512b
--- 3446,3452 ----
Karsten Hopp 65512b
      SetFocus(s_hwnd);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      /* Shorten the file name if possible */
Karsten Hopp 65512b
!     return vim_strsave(shorten_fname1((char_u *)fileBuf));
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  #endif /* FEAT_BROWSE */
Karsten Hopp 65512b
  
Karsten Hopp 65512b
*** ../vim-7.1.125/src/proto/ex_docmd.pro	Sun May  6 14:46:22 2007
Karsten Hopp 65512b
--- src/proto/ex_docmd.pro	Wed Sep 26 20:30:10 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 39,44 ****
Karsten Hopp 65512b
--- 39,45 ----
Karsten Hopp 65512b
  void tabpage_new __ARGS((void));
Karsten Hopp 65512b
  void do_exedit __ARGS((exarg_T *eap, win_T *old_curwin));
Karsten Hopp 65512b
  void free_cd_dir __ARGS((void));
Karsten Hopp 65512b
+ void ex_cd __ARGS((exarg_T *eap));
Karsten Hopp 65512b
  void do_sleep __ARGS((long msec));
Karsten Hopp 65512b
  int vim_mkdir_emsg __ARGS((char_u *name, int prot));
Karsten Hopp 65512b
  FILE *open_exfile __ARGS((char_u *fname, int forceit, char *mode));
Karsten Hopp 65512b
*** ../vim-7.1.125/src/proto/fileio.pro	Sat Sep 29 14:15:00 2007
Karsten Hopp 65512b
--- src/proto/fileio.pro	Wed Sep 26 20:05:02 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 6,11 ****
Karsten Hopp 65512b
--- 6,12 ----
Karsten Hopp 65512b
  int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering));
Karsten Hopp 65512b
  void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
Karsten Hopp 65512b
  void msg_add_lines __ARGS((int insert_space, long lnum, long nchars));
Karsten Hopp 65512b
+ char_u *shorten_fname1 __ARGS((char_u *full_path));
Karsten Hopp 65512b
  char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name));
Karsten Hopp 65512b
  void shorten_fnames __ARGS((int force));
Karsten Hopp 65512b
  void shorten_filenames __ARGS((char_u **fnames, int count));
Karsten Hopp 65512b
*** ../vim-7.1.125/src/quickfix.c	Sun Sep 16 13:26:56 2007
Karsten Hopp 65512b
--- src/quickfix.c	Sun Sep 30 13:58:38 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 2972,2977 ****
Karsten Hopp 65512b
--- 2972,2978 ----
Karsten Hopp 65512b
      regmmatch_T	regmatch;
Karsten Hopp 65512b
      int		fcount;
Karsten Hopp 65512b
      char_u	**fnames;
Karsten Hopp 65512b
+     char_u	*fname;
Karsten Hopp 65512b
      char_u	*s;
Karsten Hopp 65512b
      char_u	*p;
Karsten Hopp 65512b
      int		fi;
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 2995,3000 ****
Karsten Hopp 65512b
--- 2996,3004 ----
Karsten Hopp 65512b
      int		flags = 0;
Karsten Hopp 65512b
      colnr_T	col;
Karsten Hopp 65512b
      long	tomatch;
Karsten Hopp 65512b
+     char_u	dirname_start[MAXPATHL];
Karsten Hopp 65512b
+     char_u	dirname_now[MAXPATHL];
Karsten Hopp 65512b
+     char_u	*target_dir = NULL;
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      switch (eap->cmdidx)
Karsten Hopp 65512b
      {
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3069,3085 ****
Karsten Hopp 65512b
  	goto theend;
Karsten Hopp 65512b
      }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
      seconds = (time_t)0;
Karsten Hopp 65512b
      for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
Karsten Hopp 65512b
      {
Karsten Hopp 65512b
  	if (time(NULL) > seconds)
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
! 	    /* Display the file name every second or so. */
Karsten Hopp 65512b
  	    seconds = time(NULL);
Karsten Hopp 65512b
  	    msg_start();
Karsten Hopp 65512b
! 	    p = msg_strtrunc(fnames[fi], TRUE);
Karsten Hopp 65512b
  	    if (p == NULL)
Karsten Hopp 65512b
! 		msg_outtrans(fnames[fi]);
Karsten Hopp 65512b
  	    else
Karsten Hopp 65512b
  	    {
Karsten Hopp 65512b
  		msg_outtrans(p);
Karsten Hopp 65512b
--- 3073,3095 ----
Karsten Hopp 65512b
  	goto theend;
Karsten Hopp 65512b
      }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
+     /* Remember the current directory, because a BufRead autocommand that does
Karsten Hopp 65512b
+      * ":lcd %:p:h" changes the meaning of short path names. */
Karsten Hopp 65512b
+     mch_dirname(dirname_start, MAXPATHL);
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
      seconds = (time_t)0;
Karsten Hopp 65512b
      for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
Karsten Hopp 65512b
      {
Karsten Hopp 65512b
+ 	fname = shorten_fname1(fnames[fi]);
Karsten Hopp 65512b
  	if (time(NULL) > seconds)
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
! 	    /* Display the file name every second or so, show the user we are
Karsten Hopp 65512b
! 	     * working on it. */
Karsten Hopp 65512b
  	    seconds = time(NULL);
Karsten Hopp 65512b
  	    msg_start();
Karsten Hopp 65512b
! 	    p = msg_strtrunc(fname, TRUE);
Karsten Hopp 65512b
  	    if (p == NULL)
Karsten Hopp 65512b
! 		msg_outtrans(fname);
Karsten Hopp 65512b
  	    else
Karsten Hopp 65512b
  	    {
Karsten Hopp 65512b
  		msg_outtrans(p);
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3111,3117 ****
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	    /* Load file into a buffer, so that 'fileencoding' is detected,
Karsten Hopp 65512b
  	     * autocommands applied, etc. */
Karsten Hopp 65512b
! 	    buf = load_dummy_buffer(fnames[fi]);
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	    p_mls = save_mls;
Karsten Hopp 65512b
  #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
Karsten Hopp 65512b
--- 3121,3139 ----
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	    /* Load file into a buffer, so that 'fileencoding' is detected,
Karsten Hopp 65512b
  	     * autocommands applied, etc. */
Karsten Hopp 65512b
! 	    buf = load_dummy_buffer(fname);
Karsten Hopp 65512b
! 
Karsten Hopp 65512b
! 	    /* When autocommands changed directory: go back.  We assume it was
Karsten Hopp 65512b
! 	     * ":lcd %:p:h". */
Karsten Hopp 65512b
! 	    mch_dirname(dirname_now, MAXPATHL);
Karsten Hopp 65512b
! 	    if (STRCMP(dirname_start, dirname_now) != 0)
Karsten Hopp 65512b
! 	    {
Karsten Hopp 65512b
! 		exarg_T ea;
Karsten Hopp 65512b
! 
Karsten Hopp 65512b
! 		ea.arg = dirname_start;
Karsten Hopp 65512b
! 		ea.cmdidx = CMD_lcd;
Karsten Hopp 65512b
! 		ex_cd(&ea);
Karsten Hopp 65512b
! 	    }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  	    p_mls = save_mls;
Karsten Hopp 65512b
  #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3125,3131 ****
Karsten Hopp 65512b
  	if (buf == NULL)
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
  	    if (!got_int)
Karsten Hopp 65512b
! 		smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
Karsten Hopp 65512b
  	}
Karsten Hopp 65512b
  	else
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
--- 3147,3153 ----
Karsten Hopp 65512b
  	if (buf == NULL)
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
  	    if (!got_int)
Karsten Hopp 65512b
! 		smsg((char_u *)_("Cannot open file \"%s\""), fname);
Karsten Hopp 65512b
  	}
Karsten Hopp 65512b
  	else
Karsten Hopp 65512b
  	{
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3139,3147 ****
Karsten Hopp 65512b
  		while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
Karsten Hopp 65512b
  								     col) > 0)
Karsten Hopp 65512b
  		{
Karsten Hopp 65512b
  		    if (qf_add_entry(qi, &prevp,
Karsten Hopp 65512b
  				NULL,       /* dir */
Karsten Hopp 65512b
! 				fnames[fi],
Karsten Hopp 65512b
  				0,
Karsten Hopp 65512b
  				ml_get_buf(buf,
Karsten Hopp 65512b
  				     regmatch.startpos[0].lnum + lnum, FALSE),
Karsten Hopp 65512b
--- 3161,3170 ----
Karsten Hopp 65512b
  		while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
Karsten Hopp 65512b
  								     col) > 0)
Karsten Hopp 65512b
  		{
Karsten Hopp 65512b
+ 		    ;
Karsten Hopp 65512b
  		    if (qf_add_entry(qi, &prevp,
Karsten Hopp 65512b
  				NULL,       /* dir */
Karsten Hopp 65512b
! 				fname,
Karsten Hopp 65512b
  				0,
Karsten Hopp 65512b
  				ml_get_buf(buf,
Karsten Hopp 65512b
  				     regmatch.startpos[0].lnum + lnum, FALSE),
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3209,3214 ****
Karsten Hopp 65512b
--- 3232,3244 ----
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  		if (buf != NULL)
Karsten Hopp 65512b
  		{
Karsten Hopp 65512b
+ 		    /* If the buffer is still loaded we need to use the
Karsten Hopp 65512b
+ 		     * directory we jumped to below. */
Karsten Hopp 65512b
+ 		    if (buf == first_match_buf
Karsten Hopp 65512b
+ 			    && target_dir == NULL
Karsten Hopp 65512b
+ 			    && STRCMP(dirname_start, dirname_now) != 0)
Karsten Hopp 65512b
+ 			target_dir = vim_strsave(dirname_now);
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
  		    /* The buffer is still loaded, the Filetype autocommands
Karsten Hopp 65512b
  		     * need to be done now, in that buffer.  And the modelines
Karsten Hopp 65512b
  		     * need to be done (again).  But not the window-local
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3252,3257 ****
Karsten Hopp 65512b
--- 3282,3297 ----
Karsten Hopp 65512b
  		/* If we jumped to another buffer redrawing will already be
Karsten Hopp 65512b
  		 * taken care of. */
Karsten Hopp 65512b
  		redraw_for_dummy = FALSE;
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
+ 	    /* Jump to the directory used after loading the buffer. */
Karsten Hopp 65512b
+ 	    if (curbuf == first_match_buf && target_dir != NULL)
Karsten Hopp 65512b
+ 	    {
Karsten Hopp 65512b
+ 		exarg_T ea;
Karsten Hopp 65512b
+ 
Karsten Hopp 65512b
+ 		ea.arg = target_dir;
Karsten Hopp 65512b
+ 		ea.cmdidx = CMD_lcd;
Karsten Hopp 65512b
+ 		ex_cd(&ea);
Karsten Hopp 65512b
+ 	    }
Karsten Hopp 65512b
  	}
Karsten Hopp 65512b
      }
Karsten Hopp 65512b
      else
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 3269,3274 ****
Karsten Hopp 65512b
--- 3309,3315 ----
Karsten Hopp 65512b
      }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
  theend:
Karsten Hopp 65512b
+     vim_free(target_dir);
Karsten Hopp 65512b
      vim_free(regmatch.regprog);
Karsten Hopp 65512b
  }
Karsten Hopp 65512b
  
Karsten Hopp 65512b
*** ../vim-7.1.125/src/version.c	Sat Sep 29 14:15:00 2007
Karsten Hopp 65512b
--- src/version.c	Sun Sep 30 13:41:30 2007
Karsten Hopp 65512b
***************
Karsten Hopp 65512b
*** 668,669 ****
Karsten Hopp 65512b
--- 668,671 ----
Karsten Hopp 65512b
  {   /* Add new patch number below this line */
Karsten Hopp 65512b
+ /**/
Karsten Hopp 65512b
+     126,
Karsten Hopp 65512b
  /**/
Karsten Hopp 65512b
Karsten Hopp 65512b
-- 
Karsten Hopp 65512b
The MS-Windows registry is no more hostile than any other bunch of state
Karsten Hopp 65512b
information... that is held in a binary format... a format that nobody
Karsten Hopp 65512b
understands... and is replicated and cached in a complex and largely
Karsten Hopp 65512b
undocumented way... and contains large amounts of duplicate and obfuscated
Karsten Hopp 65512b
information...  (Ben Peterson)
Karsten Hopp 65512b
Karsten Hopp 65512b
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 65512b
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 65512b
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 65512b
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///