Karsten Hopp 0fdb61
To: vim-dev@vim.org
Karsten Hopp 0fdb61
Subject: Patch 7.1.186
Karsten Hopp 0fdb61
Fcc: outbox
Karsten Hopp 0fdb61
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 0fdb61
Mime-Version: 1.0
Karsten Hopp 0fdb61
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 0fdb61
Content-Transfer-Encoding: 8bit
Karsten Hopp 0fdb61
------------
Karsten Hopp 0fdb61
Karsten Hopp 0fdb61
Patch 7.1.186
Karsten Hopp 0fdb61
Problem:    "expand('<afile>')" returns a bogus value after changing
Karsten Hopp 0fdb61
	    directory. (Dave Fishburn)
Karsten Hopp 0fdb61
Solution:   Copy "autocmd_fname" to allocated memory and expand to full
Karsten Hopp 0fdb61
	    filename.  Shorten the path when expanding <afile>.
Karsten Hopp 0fdb61
Files:	    src/ex_docmd.c, src/fileio.c
Karsten Hopp 0fdb61
Karsten Hopp 0fdb61
Karsten Hopp 0fdb61
*** ../vim-7.1.185/src/ex_docmd.c	Wed Jan  2 15:12:29 2008
Karsten Hopp 0fdb61
--- src/ex_docmd.c	Wed Jan  2 20:12:33 2008
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 7799,7804 ****
Karsten Hopp 0fdb61
--- 7799,7805 ----
Karsten Hopp 0fdb61
  free_cd_dir()
Karsten Hopp 0fdb61
  {
Karsten Hopp 0fdb61
      vim_free(prev_dir);
Karsten Hopp 0fdb61
+     prev_dir = NULL;
Karsten Hopp 0fdb61
  }
Karsten Hopp 0fdb61
  #endif
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 9521,9526 ****
Karsten Hopp 0fdb61
--- 9522,9528 ----
Karsten Hopp 0fdb61
  		    *errormsg = (char_u *)_("E495: no autocommand file name to substitute for \"<afile>\"");
Karsten Hopp 0fdb61
  		    return NULL;
Karsten Hopp 0fdb61
  		}
Karsten Hopp 0fdb61
+ 		result = shorten_fname1(result);
Karsten Hopp 0fdb61
  		break;
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
  	case SPEC_ABUF:		/* buffer number for autocommand */
Karsten Hopp 0fdb61
*** ../vim-7.1.185/src/fileio.c	Thu Nov  8 20:47:34 2007
Karsten Hopp 0fdb61
--- src/fileio.c	Wed Jan  2 20:21:43 2008
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 5556,5562 ****
Karsten Hopp 0fdb61
  #endif
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
  #if defined(FEAT_VIMINFO) || defined(FEAT_BROWSE) || \
Karsten Hopp 0fdb61
!     defined(FEAT_QUICKFIX) || defined(PROTO)
Karsten Hopp 0fdb61
  /*
Karsten Hopp 0fdb61
   * Try to find a shortname by comparing the fullname with the current
Karsten Hopp 0fdb61
   * directory.
Karsten Hopp 0fdb61
--- 5556,5562 ----
Karsten Hopp 0fdb61
  #endif
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
  #if defined(FEAT_VIMINFO) || defined(FEAT_BROWSE) || \
Karsten Hopp 0fdb61
!     defined(FEAT_QUICKFIX) || defined(FEAT_AUTOCMD) || defined(PROTO)
Karsten Hopp 0fdb61
  /*
Karsten Hopp 0fdb61
   * Try to find a shortname by comparing the fullname with the current
Karsten Hopp 0fdb61
   * directory.
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 8546,8551 ****
Karsten Hopp 0fdb61
--- 8546,8553 ----
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
      /*
Karsten Hopp 0fdb61
       * Set the file name to be used for <afile>.
Karsten Hopp 0fdb61
+      * Make a copy to avoid that changing a buffer name or directory makes it
Karsten Hopp 0fdb61
+      * invalid.
Karsten Hopp 0fdb61
       */
Karsten Hopp 0fdb61
      if (fname_io == NULL)
Karsten Hopp 0fdb61
      {
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 8558,8563 ****
Karsten Hopp 0fdb61
--- 8560,8567 ----
Karsten Hopp 0fdb61
      }
Karsten Hopp 0fdb61
      else
Karsten Hopp 0fdb61
  	autocmd_fname = fname_io;
Karsten Hopp 0fdb61
+     if (autocmd_fname != NULL)
Karsten Hopp 0fdb61
+ 	autocmd_fname = FullName_save(autocmd_fname, FALSE);
Karsten Hopp 0fdb61
  
Karsten Hopp 0fdb61
      /*
Karsten Hopp 0fdb61
       * Set the buffer number to be used for <abuf>.
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 8740,8745 ****
Karsten Hopp 0fdb61
--- 8744,8750 ----
Karsten Hopp 0fdb61
      vim_free(sourcing_name);
Karsten Hopp 0fdb61
      sourcing_name = save_sourcing_name;
Karsten Hopp 0fdb61
      sourcing_lnum = save_sourcing_lnum;
Karsten Hopp 0fdb61
+     vim_free(autocmd_fname);
Karsten Hopp 0fdb61
      autocmd_fname = save_autocmd_fname;
Karsten Hopp 0fdb61
      autocmd_bufnr = save_autocmd_bufnr;
Karsten Hopp 0fdb61
      autocmd_match = save_autocmd_match;
Karsten Hopp 0fdb61
*** ../vim-7.1.185/src/version.c	Wed Jan  2 17:48:24 2008
Karsten Hopp 0fdb61
--- src/version.c	Wed Jan  2 21:06:35 2008
Karsten Hopp 0fdb61
***************
Karsten Hopp 0fdb61
*** 668,669 ****
Karsten Hopp 0fdb61
--- 668,671 ----
Karsten Hopp 0fdb61
  {   /* Add new patch number below this line */
Karsten Hopp 0fdb61
+ /**/
Karsten Hopp 0fdb61
+     186,
Karsten Hopp 0fdb61
  /**/
Karsten Hopp 0fdb61
Karsten Hopp 0fdb61
-- 
Karsten Hopp 0fdb61
   LAUNCELOT leaps into SHOT with a mighty cry and runs the GUARD through and
Karsten Hopp 0fdb61
   hacks him to the floor.  Blood.  Swashbuckling music (perhaps).
Karsten Hopp 0fdb61
   LAUNCELOT races through into the castle screaming.
Karsten Hopp 0fdb61
SECOND SENTRY: Hey!
Karsten Hopp 0fdb61
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 0fdb61
Karsten Hopp 0fdb61
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 0fdb61
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 0fdb61
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 0fdb61
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///