home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.299 < prev    next >
Encoding:
Internet Message Format  |  2008-05-27  |  9.3 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.1.299
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.1.299
  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
  13.         characters.
  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
  17.  
  18.  
  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
  21. ***************
  22. *** 1,4 ****
  23. ! *eval.txt*      For Vim version 7.1.  Last change: 2008 Feb 20
  24.   
  25.   
  26.             VIM REFERENCE MANUAL    by Bram Moolenaar
  27. --- 1,4 ----
  28. ! *eval.txt*      For Vim version 7.1.  Last change: 2008 May 28
  29.   
  30.   
  31.             VIM REFERENCE MANUAL    by Bram Moolenaar
  32. ***************
  33. *** 1609,1614 ****
  34. --- 1652,1658 ----
  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
  42. ***************
  43. *** 2620,2625 ****
  44. --- 2669,2687 ----
  45.   <        Searches from the directory of the current file upwards until
  46.           it finds the file "tags.vim".
  47.   
  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
  54. +         value of 'isfname'.
  55. +         Example: >
  56. +             :let fname = 'some str%nge|name'
  57. +             :exe "edit " . fnameescape(fname)
  58. + <        results in executing: >
  59. +             edit some\ str\%nge\|name
  60.   fnamemodify({fname}, {mods})                *fnamemodify()*
  61.           Modify file name {fname} according to {mods}.  {mods} is a
  62.           string of characters like it is used for file names on the
  63. *** ../vim-7.1.298/runtime/filetype.vim    Tue May 15 09:14:33 2007
  64. --- runtime/filetype.vim    Wed May 28 16:39:09 2008
  65. ***************
  66. *** 16,35 ****
  67.   augroup filetypedetect
  68.   
  69.   " Ignored extensions
  70.   au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
  71. !     \ exe "doau filetypedetect BufRead " . expand("<afile>:r")
  72.   au BufNewFile,BufRead *~
  73.       \ let s:name = expand("<afile>") |
  74.       \ let s:short = substitute(s:name, '\~$', '', '') |
  75.       \ if s:name != s:short && s:short != "" |
  76. !     \   exe "doau filetypedetect BufRead " . s:short |
  77.       \ endif |
  78. !     \ unlet s:name |
  79. !     \ unlet s:short
  80.   au BufNewFile,BufRead ?\+.in
  81.       \ if expand("<afile>:t") != "configure.in" |
  82. !     \   exe "doau filetypedetect BufRead " . expand("<afile>:r") |
  83.       \ endif
  84.   
  85.   " Pattern used to match file names which should not be inspected.
  86.   " Currently finds compressed files.
  87. --- 16,38 ----
  88.   augroup filetypedetect
  89.   
  90.   " Ignored extensions
  91. + if exists("*fnameescape")
  92.   au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.rpmsave,?\+.rpmnew
  93. !     \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
  94.   au BufNewFile,BufRead *~
  95.       \ let s:name = expand("<afile>") |
  96.       \ let s:short = substitute(s:name, '\~$', '', '') |
  97.       \ if s:name != s:short && s:short != "" |
  98. !     \   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
  99.       \ endif |
  100. !     \ unlet s:name s:short
  101.   au BufNewFile,BufRead ?\+.in
  102.       \ if expand("<afile>:t") != "configure.in" |
  103. !     \   exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
  104.       \ endif
  105. + elseif &verbose > 0
  106. +   echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
  107. + endif
  108.   
  109.   " Pattern used to match file names which should not be inspected.
  110.   " Currently finds compressed files.
  111. *** ../vim-7.1.298/src/eval.c    Tue Apr  1 13:10:45 2008
  112. --- src/eval.c    Wed May 28 16:35:51 2008
  113. ***************
  114. *** 507,512 ****
  115. --- 516,522 ----
  116.   static void f_filter __ARGS((typval_T *argvars, typval_T *rettv));
  117.   static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv));
  118.   static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv));
  119. + static void f_fnameescape __ARGS((typval_T *argvars, typval_T *rettv));
  120.   static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv));
  121.   static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv));
  122.   static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv));
  123. ***************
  124. *** 7107,7112 ****
  125. --- 7437,7443 ----
  126.       {"filter",        2, 2, f_filter},
  127.       {"finddir",        1, 3, f_finddir},
  128.       {"findfile",    1, 3, f_findfile},
  129. +     {"fnameescape",    1, 1, f_fnameescape},
  130.       {"fnamemodify",    2, 2, f_fnamemodify},
  131.       {"foldclosed",    1, 1, f_foldclosed},
  132.       {"foldclosedend",    1, 1, f_foldclosedend},
  133. ***************
  134. *** 9465,9470 ****
  135. --- 9804,9822 ----
  136.   }
  137.   
  138.   /*
  139. +  * "fnameescape({string})" function
  140. +  */
  141. +     static void
  142. + f_fnameescape(argvars, rettv)
  143. +     typval_T    *argvars;
  144. +     typval_T    *rettv;
  145. + {
  146. +     rettv->vval.v_string = vim_strsave_fnameescape(
  147. +                        get_tv_string(&argvars[0]), FALSE);
  148. +     rettv->v_type = VAR_STRING;
  149. + }
  150. + /*
  151.    * "fnamemodify({fname}, {mods})" function
  152.    */
  153.       static void
  154. *** ../vim-7.1.298/src/ex_getln.c    Tue Jan 22 12:44:03 2008
  155. --- src/ex_getln.c    Mon May 26 22:14:51 2008
  156. ***************
  157. *** 3656,3677 ****
  158.   #endif
  159.               }
  160.           }
  161. ! #ifdef BACKSLASH_IN_FILENAME
  162. !         {
  163. !             char_u    buf[20];
  164. !             int        j = 0;
  165. !             /* Don't escape '[' and '{' if they are in 'isfname'. */
  166. !             for (p = PATH_ESC_CHARS; *p != NUL; ++p)
  167. !             if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
  168. !                 buf[j++] = *p;
  169. !             buf[j] = NUL;
  170. !             p = vim_strsave_escaped(files[i], buf);
  171. !         }
  172. ! #else
  173. !         p = vim_strsave_escaped(files[i],
  174. !                  xp->xp_shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
  175. ! #endif
  176.           if (p != NULL)
  177.           {
  178.               vim_free(files[i]);
  179. --- 3656,3662 ----
  180.   #endif
  181.               }
  182.           }
  183. !         p = vim_strsave_fnameescape(files[i], xp->xp_shell);
  184.           if (p != NULL)
  185.           {
  186.               vim_free(files[i]);
  187. ***************
  188. *** 3710,3715 ****
  189. --- 3695,3725 ----
  190.   }
  191.   
  192.   /*
  193. +  * Escape special characters in "fname" for when used as a file name argument
  194. +  * after a Vim command, or, when "shell" is non-zero, a shell command.
  195. +  * Returns the result in allocated memory.
  196. +  */
  197. +     char_u *
  198. + vim_strsave_fnameescape(fname, shell)
  199. +     char_u *fname;
  200. +     int    shell;
  201. + {
  202. + #ifdef BACKSLASH_IN_FILENAME
  203. +     char_u    buf[20];
  204. +     int        j = 0;
  205. +     /* Don't escape '[' and '{' if they are in 'isfname'. */
  206. +     for (p = PATH_ESC_CHARS; *p != NUL; ++p)
  207. +     if ((*p != '[' && *p != '{') || !vim_isfilec(*p))
  208. +         buf[j++] = *p;
  209. +     buf[j] = NUL;
  210. +     return vim_strsave_escaped(fname, buf);
  211. + #else
  212. +     return vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
  213. + #endif
  214. + }
  215. + /*
  216.    * Put a backslash before the file name in "pp", which is in allocated memory.
  217.    */
  218.       static void
  219. *** ../vim-7.1.298/src/proto/ex_getln.pro    Sat May  5 19:24:48 2007
  220. --- src/proto/ex_getln.pro    Mon May 26 22:14:41 2008
  221. ***************
  222. *** 24,29 ****
  223. --- 24,30 ----
  224.   void ExpandInit __ARGS((expand_T *xp));
  225.   void ExpandCleanup __ARGS((expand_T *xp));
  226.   void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
  227. + char_u *vim_strsave_fnameescape __ARGS((char_u *fname, int shell));
  228.   void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
  229.   char_u *sm_gettail __ARGS((char_u *s));
  230.   char_u *addstar __ARGS((char_u *fname, int len, int context));
  231. *** ../vim-7.1.298/src/vim.h    Sun Mar 16 16:02:47 2008
  232. --- src/vim.h    Wed May 28 16:37:50 2008
  233. ***************
  234. *** 336,345 ****
  235.   # endif
  236.   #endif
  237.   #ifdef BACKSLASH_IN_FILENAME
  238. ! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`%#")
  239.   #else
  240. ! # define PATH_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|")
  241. ! # define SHELL_ESC_CHARS ((char_u *)" \t*?[{`$\\%#'\"|<>();&!")
  242.   #endif
  243.   
  244.   #define NUMBUFLEN 30        /* length of a buffer to store a number in ASCII */
  245. --- 336,345 ----
  246.   # endif
  247.   #endif
  248.   #ifdef BACKSLASH_IN_FILENAME
  249. ! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
  250.   #else
  251. ! # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
  252. ! # define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
  253.   #endif
  254.   
  255.   #define NUMBUFLEN 30        /* length of a buffer to store a number in ASCII */
  256. *** ../vim-7.1.298/src/version.c    Sat May 10 21:37:56 2008
  257. --- src/version.c    Wed May 28 16:40:11 2008
  258. ***************
  259. *** 668,669 ****
  260. --- 673,676 ----
  261.   {   /* Add new patch number below this line */
  262. + /**/
  263. +     299,
  264.   /**/
  265.  
  266. -- 
  267. FIRST SOLDIER:  So they wouldn't be able to bring a coconut back anyway.
  268. SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together?
  269. FIRST SOLDIER:  No, they'd have to have it on a line.
  270.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  271.  
  272.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  273. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  274. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  275.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  276.