4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Filetype detection doesn't work properly for file names ending in
12 a part that is ignored and contain a space or other special
14 Solution: Escape the special characters using the new fnameescape function.
15 Files: runtime/doc/eval.txt, runtime/filetype.vim, src/eval.c,
16 src/ex_getln.c, src/proto/ex_getln.pro, src/vim.h
19 *** ../vim-7.1.298/runtime/doc/eval.txt Wed Feb 20 20:09:44 2008
20 --- runtime/doc/eval.txt Wed May 28 16:42:42 2008
23 ! *eval.txt* For Vim version 7.1. Last change: 2008 Feb 20
26 VIM REFERENCE MANUAL by Bram Moolenaar
28 ! *eval.txt* For Vim version 7.1. Last change: 2008 May 28
31 VIM REFERENCE MANUAL by Bram Moolenaar
35 String find directory {name} in {path}
36 findfile( {name}[, {path}[, {count}]])
37 String find file {name} in {path}
38 + fnameescape( {fname}) String escape special characters in {fname}
39 fnamemodify( {fname}, {mods}) String modify file name
40 foldclosed( {lnum}) Number first line of fold at {lnum} if closed
41 foldclosedend( {lnum}) Number last line of fold at {lnum} if closed
45 < Searches from the directory of the current file upwards until
46 it finds the file "tags.vim".
48 + fnameescape({string}) *fnameescape()*
49 + Escape {string} for use as file name command argument. All
50 + characters that have a special meaning, such as '%' and '|'
51 + are escaped with a backslash.
52 + For most systems the characters escaped are "". For systems
53 + where a backslash appears in a filename, it depends on the
56 + :let fname = 'some str%nge|name'
57 + :exe "edit " . fnameescape(fname)
58 + < results in executing: >
59 + edit some\ str\%nge\|name
61 fnamemodify({fname}, {mods}) *fnamemodify()*
62 Modify file name {fname} according to {mods}. {mods} is a
63 string of characters like it is used for file names on the
64 *** ../vim-7.1.298/runtime/filetype.vim Tue May 15 09:14:33 2007
65 --- runtime/filetype.vim Wed May 28 16:39:09 2008
68 augroup filetypedetect
71 au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
72 ! \ exe "doau filetypedetect BufRead " . expand("<afile>:r")
73 au BufNewFile,BufRead *~
74 \ let s:name = expand("<afile>") |
75 \ let s:short = substitute(s:name, '\~$', '', '') |
76 \ if s:name != s:short && s:short != "" |
77 ! \ exe "doau filetypedetect BufRead " . s:short |
81 au BufNewFile,BufRead ?\+.in
82 \ if expand("<afile>:t") != "configure.in" |
83 ! \ exe "doau filetypedetect BufRead " . expand("<afile>:r") |
86 " Pattern used to match file names which should not be inspected.
87 " Currently finds compressed files.
89 augroup filetypedetect
92 + if exists("*fnameescape")
93 au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
94 ! \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
95 au BufNewFile,BufRead *~
96 \ let s:name = expand("<afile>") |
97 \ let s:short = substitute(s:name, '\~$', '', '') |
98 \ if s:name != s:short && s:short != "" |
99 ! \ exe "doau filetypedetect BufRead " . fnameescape(s:short) |
101 ! \ unlet s:name s:short
102 au BufNewFile,BufRead ?\+.in
103 \ if expand("<afile>:t") != "configure.in" |
104 ! \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
106 + elseif &verbose > 0
107 + echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
110 " Pattern used to match file names which should not be inspected.
111 " Currently finds compressed files.
112 *** ../vim-7.1.298/src/eval.c Tue Apr 1 13:10:45 2008
113 --- src/eval.c Wed May 28 16:35:51 2008
117 static void f_filter __ARGS((typval_T *argvars, typval_T *rettv));
118 static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv));
119 static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv));
120 + static void f_fnameescape __ARGS((typval_T *argvars, typval_T *rettv));
121 static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv));
122 static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv));
123 static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv));
127 {"filter", 2, 2, f_filter},
128 {"finddir", 1, 3, f_finddir},
129 {"findfile", 1, 3, f_findfile},
130 + {"fnameescape", 1, 1, f_fnameescape},
131 {"fnamemodify", 2, 2, f_fnamemodify},
132 {"foldclosed", 1, 1, f_foldclosed},
133 {"foldclosedend", 1, 1, f_foldclosedend},
140 + * "fnameescape({string})" function
143 + f_fnameescape(argvars, rettv)
147 + rettv->vval.v_string = vim_strsave_fnameescape(
148 + get_tv_string(&argvars[0]), FALSE);
149 + rettv->v_type = VAR_STRING;
153 * "fnamemodify({fname}, {mods})" function
156 *** ../vim-7.1.298/src/ex_getln.c Tue Jan 22 12:44:03 2008
157 --- src/ex_getln.c Mon May 26 22:14:51 2008
163 ! #ifdef BACKSLASH_IN_FILENAME
168 ! /* Don't escape '[' and '{' if they are in 'isfname'. */
169 ! for (p = PATH_ESC_CHARS; *p != NUL; ++p)
170 ! if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
173 ! p = vim_strsave_escaped(files[i], buf);
176 ! p = vim_strsave_escaped(files[i],
177 ! xp->xp_shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
186 ! p = vim_strsave_fnameescape(files[i], xp->xp_shell);
196 + * Escape special characters in "fname" for when used as a file name argument
197 + * after a Vim command, or, when "shell" is non-zero, a shell command.
198 + * Returns the result in allocated memory.
201 + vim_strsave_fnameescape(fname, shell)
205 + #ifdef BACKSLASH_IN_FILENAME
209 + /* Don't escape '[' and '{' if they are in 'isfname'. */
210 + for (p = PATH_ESC_CHARS; *p != NUL; ++p)
211 + if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
214 + return vim_strsave_escaped(fname, buf);
216 + return vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
221 * Put a backslash before the file name in "pp", which is in allocated memory.
224 *** ../vim-7.1.298/src/proto/ex_getln.pro Sat May 5 19:24:48 2007
225 --- src/proto/ex_getln.pro Mon May 26 22:14:41 2008
229 void ExpandInit __ARGS((expand_T *xp));
230 void ExpandCleanup __ARGS((expand_T *xp));
231 void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
232 + char_u *vim_strsave_fnameescape __ARGS((char_u *fname, int shell));
233 void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
234 char_u *sm_gettail __ARGS((char_u *s));
235 char_u *addstar __ARGS((char_u *fname, int len, int context));
236 *** ../vim-7.1.298/src/vim.h Sun Mar 16 16:02:47 2008
237 --- src/vim.h Wed May 28 16:37:50 2008
242 #ifdef BACKSLASH_IN_FILENAME
243 ! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`%#")
245 ! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|")
246 ! # define SHELL_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|<>();&!")
249 #define NUMBUFLEN 30 /* length of a buffer to store a number in ASCII */
253 #ifdef BACKSLASH_IN_FILENAME
254 ! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
256 ! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
257 ! # define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
260 #define NUMBUFLEN 30 /* length of a buffer to store a number in ASCII */
261 *** ../vim-7.1.298/src/version.c Sat May 10 21:37:56 2008
262 --- src/version.c Wed May 28 16:40:11 2008
266 { /* Add new patch number below this line */
272 FIRST SOLDIER: So they wouldn't be able to bring a coconut back anyway.
273 SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together?
274 FIRST SOLDIER: No, they'd have to have it on a line.
275 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
277 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
278 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
279 \\\ download, build and distribute -- http://www.A-A-P.org ///
280 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///