]> granicus.if.org Git - vim/commitdiff
updated for version 7.1-299 v7.1.299
authorBram Moolenaar <Bram@vim.org>
Wed, 28 May 2008 14:49:58 +0000 (14:49 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 28 May 2008 14:49:58 +0000 (14:49 +0000)
runtime/doc/eval.txt
runtime/filetype.vim
src/eval.c
src/ex_getln.c
src/proto/ex_getln.pro
src/version.c
src/vim.h

index 13caa16cf17c3288d5437c4726c517ca3eaaeb8b..57e2c4e43dc2940d051f3b1c9e41fd28e6092ba7 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*      For Vim version 7.1.  Last change: 2008 Feb 20
+*eval.txt*      For Vim version 7.1.  Last change: 2008 May 28
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1609,6 +1609,7 @@ finddir( {name}[, {path}[, {count}]])
                                String  find directory {name} in {path}
 findfile( {name}[, {path}[, {count}]])
                                String  find file {name} in {path}
+fnameescape( {fname})          String  escape special characters in {fname}
 fnamemodify( {fname}, {mods})  String  modify file name
 foldclosed( {lnum})            Number  first line of fold at {lnum} if closed
 foldclosedend( {lnum})         Number  last line of fold at {lnum} if closed
@@ -2620,6 +2621,19 @@ findfile({name}[, {path}[, {count}]])                            *findfile()*
 <              Searches from the directory of the current file upwards until
                it finds the file "tags.vim".
 
+fnameescape({string})                                  *fnameescape()*
+               Escape {string} for use as file name command argument.  All
+               characters that have a special meaning, such as '%' and '|'
+               are escaped with a backslash.
+               For most systems the characters escaped are "".  For systems
+               where a backslash appears in a filename, it depends on the
+               value of 'isfname'.
+               Example: >
+                       :let fname = 'some str%nge|name'
+                       :exe "edit " . fnameescape(fname)
+<              results in executing: >
+                       edit some\ str\%nge\|name
+
 fnamemodify({fname}, {mods})                           *fnamemodify()*
                Modify file name {fname} according to {mods}.  {mods} is a
                string of characters like it is used for file names on the
index 20719aa2e432f98445a49923f063774f3c2b6733..e20a53aed46c393cfd7002672d61ac729dc6b692 100644 (file)
@@ -16,20 +16,23 @@ set cpo&vim
 augroup filetypedetect
 
 " Ignored extensions
+if exists("*fnameescape")
 au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
-       \ exe "doau filetypedetect BufRead " . expand("<afile>:r")
+       \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
 au BufNewFile,BufRead *~
        \ let s:name = expand("<afile>") |
        \ let s:short = substitute(s:name, '\~$', '', '') |
        \ if s:name != s:short && s:short != "" |
-       \   exe "doau filetypedetect BufRead " . s:short |
+       \   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
        \ endif |
-       \ unlet s:name |
-       \ unlet s:short
+       \ unlet s:name s:short
 au BufNewFile,BufRead ?\+.in
        \ if expand("<afile>:t") != "configure.in" |
-       \   exe "doau filetypedetect BufRead " . expand("<afile>:r") |
+       \   exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
        \ endif
+elseif &verbose > 0
+  echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
+endif
 
 " Pattern used to match file names which should not be inspected.
 " Currently finds compressed files.
index e008df24aacd897c0651be16b5a1db649e8739cd..34263544cb66bf7075efa6ea5c9ed6deda0dbfc0 100644 (file)
@@ -507,6 +507,7 @@ static void f_filewritable __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_filter __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_fnameescape __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7107,6 +7108,7 @@ static struct fst
     {"filter",         2, 2, f_filter},
     {"finddir",                1, 3, f_finddir},
     {"findfile",       1, 3, f_findfile},
+    {"fnameescape",    1, 1, f_fnameescape},
     {"fnamemodify",    2, 2, f_fnamemodify},
     {"foldclosed",     1, 1, f_foldclosed},
     {"foldclosedend",  1, 1, f_foldclosedend},
@@ -9464,6 +9466,19 @@ f_findfile(argvars, rettv)
     findfilendir(argvars, rettv, FINDFILE_FILE);
 }
 
+/*
+ * "fnameescape({string})" function
+ */
+    static void
+f_fnameescape(argvars, rettv)
+    typval_T   *argvars;
+    typval_T   *rettv;
+{
+    rettv->vval.v_string = vim_strsave_fnameescape(
+                                          get_tv_string(&argvars[0]), FALSE);
+    rettv->v_type = VAR_STRING;
+}
+
 /*
  * "fnamemodify({fname}, {mods})" function
  */
index e7f8c1b1c7806466ff5e4e322a37c0dd7e6bf806..b575e29983acf22fb2b0ef17106c2a12e8a8e171 100644 (file)
@@ -3656,22 +3656,7 @@ ExpandEscape(xp, str, numfiles, files, options)
 #endif
                    }
                }
-#ifdef BACKSLASH_IN_FILENAME
-               {
-                   char_u      buf[20];
-                   int         j = 0;
-
-                   /* Don't escape '[' and '{' if they are in 'isfname'. */
-                   for (p = PATH_ESC_CHARS; *p != NUL; ++p)
-                       if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
-                           buf[j++] = *p;
-                   buf[j] = NUL;
-                   p = vim_strsave_escaped(files[i], buf);
-               }
-#else
-               p = vim_strsave_escaped(files[i],
-                            xp->xp_shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
-#endif
+               p = vim_strsave_fnameescape(files[i], xp->xp_shell);
                if (p != NULL)
                {
                    vim_free(files[i]);
@@ -3709,6 +3694,31 @@ ExpandEscape(xp, str, numfiles, files, options)
     }
 }
 
+/*
+ * Escape special characters in "fname" for when used as a file name argument
+ * after a Vim command, or, when "shell" is non-zero, a shell command.
+ * Returns the result in allocated memory.
+ */
+    char_u *
+vim_strsave_fnameescape(fname, shell)
+    char_u *fname;
+    int    shell;
+{
+#ifdef BACKSLASH_IN_FILENAME
+    char_u     buf[20];
+    int                j = 0;
+
+    /* Don't escape '[' and '{' if they are in 'isfname'. */
+    for (p = PATH_ESC_CHARS; *p != NUL; ++p)
+       if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
+           buf[j++] = *p;
+    buf[j] = NUL;
+    return vim_strsave_escaped(fname, buf);
+#else
+    return vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
+#endif
+}
+
 /*
  * Put a backslash before the file name in "pp", which is in allocated memory.
  */
index f5feb201f1873144b34cf6e11525c70cc296efc0..b4a501814376b89ea25015b8940f4a3c34ccf5ea 100644 (file)
@@ -24,6 +24,7 @@ char_u *ExpandOne __ARGS((expand_T *xp, char_u *str, char_u *orig, int options,
 void ExpandInit __ARGS((expand_T *xp));
 void ExpandCleanup __ARGS((expand_T *xp));
 void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
+char_u *vim_strsave_fnameescape __ARGS((char_u *fname, int shell));
 void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
 char_u *sm_gettail __ARGS((char_u *s));
 char_u *addstar __ARGS((char_u *fname, int len, int context));
index 45b003e1d29e29ecdda0fc223d431c09c7bf04ad..7b7bdcd03dbbe93c2962379e29da578a6d8b8411 100644 (file)
@@ -666,6 +666,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    299,
 /**/
     298,
 /**/
index d93bec1545302607e0453304d40afa2e2d69ab9b..71dd3ae2daf270f0224e439e9928f39150a04561 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
 # endif
 #endif
 #ifdef BACKSLASH_IN_FILENAME
-# define PATH_ESC_CHARS ((char_u *)" \t*?[{`%#")
+# define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
 #else
-# define PATH_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|")
-# define SHELL_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|<>();&!")
+# define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
+# define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
 #endif
 
 #define NUMBUFLEN 30       /* length of a buffer to store a number in ASCII */