Karsten Hopp 83be86
To: vim-dev@vim.org
Karsten Hopp 83be86
Subject: Patch 7.1.299
Karsten Hopp 83be86
Fcc: outbox
Karsten Hopp 83be86
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 83be86
Mime-Version: 1.0
Karsten Hopp 83be86
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 83be86
Content-Transfer-Encoding: 8bit
Karsten Hopp 83be86
------------
Karsten Hopp 83be86
Karsten Hopp 83be86
Patch 7.1.299
Karsten Hopp 83be86
Problem:    Filetype detection doesn't work properly for file names ending in
Karsten Hopp 83be86
	    a part that is ignored and contain a space or other special
Karsten Hopp 83be86
	    characters.
Karsten Hopp 83be86
Solution:   Escape the special characters using the new fnameescape function.
Karsten Hopp 83be86
Files:	    runtime/doc/eval.txt, runtime/filetype.vim, src/eval.c,
Karsten Hopp 83be86
	    src/ex_getln.c, src/proto/ex_getln.pro, src/vim.h
Karsten Hopp 83be86
Karsten Hopp 83be86
Karsten Hopp 83be86
*** ../vim-7.1.298/runtime/doc/eval.txt	Wed Feb 20 20:09:44 2008
Karsten Hopp 83be86
--- runtime/doc/eval.txt	Wed May 28 16:42:42 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 1,4 ****
Karsten Hopp 83be86
! *eval.txt*      For Vim version 7.1.  Last change: 2008 Feb 20
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp 83be86
--- 1,4 ----
Karsten Hopp 83be86
! *eval.txt*      For Vim version 7.1.  Last change: 2008 May 28
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 1609,1614 ****
Karsten Hopp 83be86
--- 1652,1658 ----
Karsten Hopp 83be86
  				String	find directory {name} in {path}
Karsten Hopp 83be86
  findfile( {name}[, {path}[, {count}]])
Karsten Hopp 83be86
  				String	find file {name} in {path}
Karsten Hopp 83be86
+ fnameescape( {fname})		String	escape special characters in {fname}
Karsten Hopp 83be86
  fnamemodify( {fname}, {mods})	String	modify file name
Karsten Hopp 83be86
  foldclosed( {lnum})		Number	first line of fold at {lnum} if closed
Karsten Hopp 83be86
  foldclosedend( {lnum})		Number	last line of fold at {lnum} if closed
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 2620,2625 ****
Karsten Hopp 83be86
--- 2669,2687 ----
Karsten Hopp 83be86
  <		Searches from the directory of the current file upwards until
Karsten Hopp 83be86
  		it finds the file "tags.vim".
Karsten Hopp 83be86
  
Karsten Hopp 83be86
+ fnameescape({string})					*fnameescape()*
Karsten Hopp 83be86
+ 		Escape {string} for use as file name command argument.  All
Karsten Hopp 83be86
+ 		characters that have a special meaning, such as '%' and '|'
Karsten Hopp 83be86
+ 		are escaped with a backslash.
Karsten Hopp 83be86
+ 		For most systems the characters escaped are "".  For systems
Karsten Hopp 83be86
+ 		where a backslash appears in a filename, it depends on the
Karsten Hopp 83be86
+ 		value of 'isfname'.
Karsten Hopp 83be86
+ 		Example: >
Karsten Hopp 83be86
+ 			:let fname = 'some str%nge|name'
Karsten Hopp 83be86
+ 			:exe "edit " . fnameescape(fname)
Karsten Hopp 83be86
+ <		results in executing: >
Karsten Hopp 83be86
+ 			edit some\ str\%nge\|name
Karsten Hopp 83be86
+ 
Karsten Hopp 83be86
  fnamemodify({fname}, {mods})				*fnamemodify()*
Karsten Hopp 83be86
  		Modify file name {fname} according to {mods}.  {mods} is a
Karsten Hopp 83be86
  		string of characters like it is used for file names on the
Karsten Hopp 83be86
*** ../vim-7.1.298/runtime/filetype.vim	Tue May 15 09:14:33 2007
Karsten Hopp 83be86
--- runtime/filetype.vim	Wed May 28 16:39:09 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 16,35 ****
Karsten Hopp 83be86
  augroup filetypedetect
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  " Ignored extensions
Karsten Hopp 83be86
  au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
Karsten Hopp 83be86
! 	\ exe "doau filetypedetect BufRead " . expand("<afile>:r")
Karsten Hopp 83be86
  au BufNewFile,BufRead *~
Karsten Hopp 83be86
  	\ let s:name = expand("<afile>") |
Karsten Hopp 83be86
  	\ let s:short = substitute(s:name, '\~$', '', '') |
Karsten Hopp 83be86
  	\ if s:name != s:short && s:short != "" |
Karsten Hopp 83be86
! 	\   exe "doau filetypedetect BufRead " . s:short |
Karsten Hopp 83be86
  	\ endif |
Karsten Hopp 83be86
! 	\ unlet s:name |
Karsten Hopp 83be86
! 	\ unlet s:short
Karsten Hopp 83be86
  au BufNewFile,BufRead ?\+.in
Karsten Hopp 83be86
  	\ if expand("<afile>:t") != "configure.in" |
Karsten Hopp 83be86
! 	\   exe "doau filetypedetect BufRead " . expand("<afile>:r") |
Karsten Hopp 83be86
  	\ endif
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  " Pattern used to match file names which should not be inspected.
Karsten Hopp 83be86
  " Currently finds compressed files.
Karsten Hopp 83be86
--- 16,38 ----
Karsten Hopp 83be86
  augroup filetypedetect
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  " Ignored extensions
Karsten Hopp 83be86
+ if exists("*fnameescape")
Karsten Hopp 83be86
  au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
Karsten Hopp 83be86
! 	\ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
Karsten Hopp 83be86
  au BufNewFile,BufRead *~
Karsten Hopp 83be86
  	\ let s:name = expand("<afile>") |
Karsten Hopp 83be86
  	\ let s:short = substitute(s:name, '\~$', '', '') |
Karsten Hopp 83be86
  	\ if s:name != s:short && s:short != "" |
Karsten Hopp 83be86
! 	\   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
Karsten Hopp 83be86
  	\ endif |
Karsten Hopp 83be86
! 	\ unlet s:name s:short
Karsten Hopp 83be86
  au BufNewFile,BufRead ?\+.in
Karsten Hopp 83be86
  	\ if expand("<afile>:t") != "configure.in" |
Karsten Hopp 83be86
! 	\   exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
Karsten Hopp 83be86
  	\ endif
Karsten Hopp 83be86
+ elseif &verbose > 0
Karsten Hopp 83be86
+   echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
Karsten Hopp 83be86
+ endif
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  " Pattern used to match file names which should not be inspected.
Karsten Hopp 83be86
  " Currently finds compressed files.
Karsten Hopp 83be86
*** ../vim-7.1.298/src/eval.c	Tue Apr  1 13:10:45 2008
Karsten Hopp 83be86
--- src/eval.c	Wed May 28 16:35:51 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 507,512 ****
Karsten Hopp 83be86
--- 516,522 ----
Karsten Hopp 83be86
  static void f_filter __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
  static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
  static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
+ static void f_fnameescape __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
  static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
  static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
  static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 7107,7112 ****
Karsten Hopp 83be86
--- 7437,7443 ----
Karsten Hopp 83be86
      {"filter",		2, 2, f_filter},
Karsten Hopp 83be86
      {"finddir",		1, 3, f_finddir},
Karsten Hopp 83be86
      {"findfile",	1, 3, f_findfile},
Karsten Hopp 83be86
+     {"fnameescape",	1, 1, f_fnameescape},
Karsten Hopp 83be86
      {"fnamemodify",	2, 2, f_fnamemodify},
Karsten Hopp 83be86
      {"foldclosed",	1, 1, f_foldclosed},
Karsten Hopp 83be86
      {"foldclosedend",	1, 1, f_foldclosedend},
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 9465,9470 ****
Karsten Hopp 83be86
--- 9804,9822 ----
Karsten Hopp 83be86
  }
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  /*
Karsten Hopp 83be86
+  * "fnameescape({string})" function
Karsten Hopp 83be86
+  */
Karsten Hopp 83be86
+     static void
Karsten Hopp 83be86
+ f_fnameescape(argvars, rettv)
Karsten Hopp 83be86
+     typval_T	*argvars;
Karsten Hopp 83be86
+     typval_T	*rettv;
Karsten Hopp 83be86
+ {
Karsten Hopp 83be86
+     rettv->vval.v_string = vim_strsave_fnameescape(
Karsten Hopp 83be86
+ 					   get_tv_string(&argvars[0]), FALSE);
Karsten Hopp 83be86
+     rettv->v_type = VAR_STRING;
Karsten Hopp 83be86
+ }
Karsten Hopp 83be86
+ 
Karsten Hopp 83be86
+ /*
Karsten Hopp 83be86
   * "fnamemodify({fname}, {mods})" function
Karsten Hopp 83be86
   */
Karsten Hopp 83be86
      static void
Karsten Hopp 83be86
*** ../vim-7.1.298/src/ex_getln.c	Tue Jan 22 12:44:03 2008
Karsten Hopp 83be86
--- src/ex_getln.c	Mon May 26 22:14:51 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 3656,3677 ****
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  		    }
Karsten Hopp 83be86
  		}
Karsten Hopp 83be86
! #ifdef BACKSLASH_IN_FILENAME
Karsten Hopp 83be86
! 		{
Karsten Hopp 83be86
! 		    char_u	buf[20];
Karsten Hopp 83be86
! 		    int		j = 0;
Karsten Hopp 83be86
! 
Karsten Hopp 83be86
! 		    /* Don't escape '[' and '{' if they are in 'isfname'. */
Karsten Hopp 83be86
! 		    for (p = PATH_ESC_CHARS; *p != NUL; ++p)
Karsten Hopp 83be86
! 			if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
Karsten Hopp 83be86
! 			    buf[j++] = *p;
Karsten Hopp 83be86
! 		    buf[j] = NUL;
Karsten Hopp 83be86
! 		    p = vim_strsave_escaped(files[i], buf);
Karsten Hopp 83be86
! 		}
Karsten Hopp 83be86
! #else
Karsten Hopp 83be86
! 		p = vim_strsave_escaped(files[i],
Karsten Hopp 83be86
! 			     xp->xp_shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
Karsten Hopp 83be86
! #endif
Karsten Hopp 83be86
  		if (p != NULL)
Karsten Hopp 83be86
  		{
Karsten Hopp 83be86
  		    vim_free(files[i]);
Karsten Hopp 83be86
--- 3656,3662 ----
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  		    }
Karsten Hopp 83be86
  		}
Karsten Hopp 83be86
! 		p = vim_strsave_fnameescape(files[i], xp->xp_shell);
Karsten Hopp 83be86
  		if (p != NULL)
Karsten Hopp 83be86
  		{
Karsten Hopp 83be86
  		    vim_free(files[i]);
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 3710,3715 ****
Karsten Hopp 83be86
--- 3695,3725 ----
Karsten Hopp 83be86
  }
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  /*
Karsten Hopp 83be86
+  * Escape special characters in "fname" for when used as a file name argument
Karsten Hopp 83be86
+  * after a Vim command, or, when "shell" is non-zero, a shell command.
Karsten Hopp 83be86
+  * Returns the result in allocated memory.
Karsten Hopp 83be86
+  */
Karsten Hopp 83be86
+     char_u *
Karsten Hopp 83be86
+ vim_strsave_fnameescape(fname, shell)
Karsten Hopp 83be86
+     char_u *fname;
Karsten Hopp 83be86
+     int    shell;
Karsten Hopp 83be86
+ {
Karsten Hopp 83be86
+ #ifdef BACKSLASH_IN_FILENAME
Karsten Hopp 83be86
+     char_u	buf[20];
Karsten Hopp 83be86
+     int		j = 0;
Karsten Hopp 83be86
+ 
Karsten Hopp 83be86
+     /* Don't escape '[' and '{' if they are in 'isfname'. */
Karsten Hopp 83be86
+     for (p = PATH_ESC_CHARS; *p != NUL; ++p)
Karsten Hopp 83be86
+ 	if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
Karsten Hopp 83be86
+ 	    buf[j++] = *p;
Karsten Hopp 83be86
+     buf[j] = NUL;
Karsten Hopp 83be86
+     return vim_strsave_escaped(fname, buf);
Karsten Hopp 83be86
+ #else
Karsten Hopp 83be86
+     return vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
Karsten Hopp 83be86
+ #endif
Karsten Hopp 83be86
+ }
Karsten Hopp 83be86
+ 
Karsten Hopp 83be86
+ /*
Karsten Hopp 83be86
   * Put a backslash before the file name in "pp", which is in allocated memory.
Karsten Hopp 83be86
   */
Karsten Hopp 83be86
      static void
Karsten Hopp 83be86
*** ../vim-7.1.298/src/proto/ex_getln.pro	Sat May  5 19:24:48 2007
Karsten Hopp 83be86
--- src/proto/ex_getln.pro	Mon May 26 22:14:41 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 24,29 ****
Karsten Hopp 83be86
--- 24,30 ----
Karsten Hopp 83be86
  void ExpandInit __ARGS((expand_T *xp));
Karsten Hopp 83be86
  void ExpandCleanup __ARGS((expand_T *xp));
Karsten Hopp 83be86
  void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
Karsten Hopp 83be86
+ char_u *vim_strsave_fnameescape __ARGS((char_u *fname, int shell));
Karsten Hopp 83be86
  void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
Karsten Hopp 83be86
  char_u *sm_gettail __ARGS((char_u *s));
Karsten Hopp 83be86
  char_u *addstar __ARGS((char_u *fname, int len, int context));
Karsten Hopp 83be86
*** ../vim-7.1.298/src/vim.h	Sun Mar 16 16:02:47 2008
Karsten Hopp 83be86
--- src/vim.h	Wed May 28 16:37:50 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 336,345 ****
Karsten Hopp 83be86
  # endif
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  #ifdef BACKSLASH_IN_FILENAME
Karsten Hopp 83be86
! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`%#")
Karsten Hopp 83be86
  #else
Karsten Hopp 83be86
! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|")
Karsten Hopp 83be86
! # define SHELL_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|<>();&!")
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  #define NUMBUFLEN 30	    /* length of a buffer to store a number in ASCII */
Karsten Hopp 83be86
--- 336,345 ----
Karsten Hopp 83be86
  # endif
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  #ifdef BACKSLASH_IN_FILENAME
Karsten Hopp 83be86
! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
Karsten Hopp 83be86
  #else
Karsten Hopp 83be86
! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
Karsten Hopp 83be86
! # define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
Karsten Hopp 83be86
  #endif
Karsten Hopp 83be86
  
Karsten Hopp 83be86
  #define NUMBUFLEN 30	    /* length of a buffer to store a number in ASCII */
Karsten Hopp 83be86
*** ../vim-7.1.298/src/version.c	Sat May 10 21:37:56 2008
Karsten Hopp 83be86
--- src/version.c	Wed May 28 16:40:11 2008
Karsten Hopp 83be86
***************
Karsten Hopp 83be86
*** 668,669 ****
Karsten Hopp 83be86
--- 673,676 ----
Karsten Hopp 83be86
  {   /* Add new patch number below this line */
Karsten Hopp 83be86
+ /**/
Karsten Hopp 83be86
+     299,
Karsten Hopp 83be86
  /**/
Karsten Hopp 83be86
Karsten Hopp 83be86
-- 
Karsten Hopp 83be86
FIRST SOLDIER:  So they wouldn't be able to bring a coconut back anyway.
Karsten Hopp 83be86
SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together?
Karsten Hopp 83be86
FIRST SOLDIER:  No, they'd have to have it on a line.
Karsten Hopp 83be86
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 83be86
Karsten Hopp 83be86
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 83be86
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 83be86
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 83be86
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///