]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.191 v7.4.191
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Feb 2014 22:39:13 +0000 (23:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Feb 2014 22:39:13 +0000 (23:39 +0100)
Problem:    Escaping a file name for shell commands can't be done without a
            function.
Solution:   Add the :S file name modifier.

20 files changed:
runtime/doc/eval.txt
runtime/doc/options.txt
runtime/doc/quickfix.txt
runtime/doc/usr_30.txt
runtime/doc/usr_40.txt
runtime/doc/usr_42.txt
runtime/doc/vi_diff.txt
src/eval.c
src/misc2.c
src/normal.c
src/proto/misc2.pro
src/testdir/Make_amiga.mak
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Make_os2.mak
src/testdir/Make_vms.mms
src/testdir/Makefile
src/testdir/test105.in [new file with mode: 0644]
src/testdir/test105.ok [new file with mode: 0644]
src/version.c

index 7d6708a679645f9ee3b21e50da9cbb883e2c287c..7b57e7fd4bfce8858d7d2a7b3601b6ccedbabbc0 100644 (file)
@@ -5428,6 +5428,7 @@ shellescape({string} [, {special}])                       *shellescape()*
 <              This results in a directory listing for the file under the
                cursor.  Example of use with |system()|: >
                    :call system("chmod +w -- " . shellescape(expand("%")))
+<              See also |::S|.
 
 
 shiftwidth()                                           *shiftwidth()*
@@ -5910,14 +5911,16 @@ system({expr} [, {input}])                              *system()* *E677*
                passed as stdin to the command.  The string is written as-is,
                you need to take care of using the correct line separators
                yourself.  Pipes are not used.
-               Note: Use |shellescape()| to escape special characters in a
-               command argument.  Newlines in {expr} may cause the command to
-               fail.  The characters in 'shellquote' and 'shellxquote' may
-               also cause trouble.
+               Note: Use |shellescape()| or |::S| with |expand()| or 
+               |fnamemodify()| to escape special characters in a command 
+               argument.  Newlines in {expr} may cause the command to fail.  
+               The characters in 'shellquote' and 'shellxquote' may also 
+               cause trouble.
                This is not to be used for interactive commands.
 
                The result is a String.  Example: >
                    :let files = system("ls " .  shellescape(expand('%:h')))
+                   :let files = system('ls ' . expand('%:h:S'))
 
 <              To make the result more system-independent, the shell output
                is filtered to replace <CR> with <NL> for Macintosh, and
index 95e095006629909aa40cbe99657a40905bf13c31..9fb67a2cff3336f152a630b07cb2f11063817a02 100644 (file)
@@ -4757,8 +4757,9 @@ A jump table for the options with a short description can be found at |Q_op|.
                        global or local to buffer |global-local|
                        {not in Vi}
        Program to use for the ":make" command.  See |:make_makeprg|.
-       This option may contain '%' and '#' characters, which are expanded to
-       the current and alternate file name. |:_%| |:_#|
+       This option may contain '%' and '#' characters (see  |:_%| and |:_#|), 
+       which are expanded to the current and alternate file name.  Use |::S| 
+       to escape file names in case they contain special characters.
        Environment variables are expanded |:set_env|.  See |option-backslash|
        about including spaces and backslashes.
        Note that a '|' must be escaped twice: once for ":set" and once for
index d6bf938c41ad383aa5c6af0f7102d522a70314e7..f82dd1fbf06661d509433ae3b6f04ebe63cedf44 100644 (file)
@@ -838,7 +838,7 @@ Unfortunately, there is no standard way to run the tests.
 The alltests.py script seems to be used quite often, that's all.
 Useful values for the 'makeprg' options therefore are:
  setlocal makeprg=./alltests.py " Run a testsuite
- setlocal makeprg=python %      " Run a single testcase
+ setlocal makeprg=python\ %:S   " Run a single testcase
 
 Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
 
@@ -1332,7 +1332,7 @@ or: >
 Here is an alternative from Michael F. Lamb for Unix that filters the errors
 first: >
   :setl errorformat=%Z%f:%l:\ %m,%A%p^,%-G%*[^sl]%.%#
-  :setl makeprg=javac\ %\ 2>&1\ \\\|\ vim-javac-filter
+  :setl makeprg=javac\ %:S\ 2>&1\ \\\|\ vim-javac-filter
 
 You need to put the following in "vim-javac-filter" somewhere in your path
 (e.g., in ~/bin) and make it executable: >
index 52f4375726d07ea086e4c29c2d7049042fee82b6..b2be512980adb7e2d373372462be0472396a324f 100644 (file)
@@ -128,7 +128,7 @@ be escaped with a backslash.  Example: >
 You can include special Vim keywords in the command specification.  The %
 character expands to the name of the current file.  So if you execute the
 command: >
-       :set makeprg=make\ %
+       :set makeprg=make\ %:S
 
 When you are editing main.c, then ":make" executes the following command: >
 
@@ -137,7 +137,7 @@ When you are editing main.c, then ":make" executes the following command: >
 This is not too useful, so you will refine the command a little and use the :r
 (root) modifier: >
 
-       :set makeprg=make\ %:r.o
+       :set makeprg=make\ %:r:S.o
 
 Now the command executed is as follows: >
 
index b1108a5c33acfbe442147ef4fbb1ec69c60d174f..9d706481df138e9e6b831885e16900d99c4e50df 100644 (file)
@@ -209,7 +209,7 @@ The ":map" command can be followed by another command.  A | character
 separates the two commands.  This also means that a | character can't be used
 inside a map command.  To include one, use <Bar> (five characters).  Example:
 >
-       :map <F8> :write <Bar> !checkin %<CR>
+       :map <F8> :write <Bar> !checkin %:S<CR>
 
 The same problem applies to the ":unmap" command, with the addition that you
 have to watch out for trailing white space.  These two commands are different:
index a1cd533e2640ac32ae78bb2906d0f55d673fb019..1d16112aa0994c9401bd8e5eb395ef9ec56b818f 100644 (file)
@@ -311,7 +311,7 @@ redefine what these items do (after the default menus are setup).
 item with a bitmap.  For example, define a new toolbar item with: >
 
        :tmenu ToolBar.Compile  Compile the current file
-       :amenu ToolBar.Compile  :!cc % -o %:r<CR>
+       :amenu ToolBar.Compile  :!cc %:S -o %:r:S<CR>
 
 Now you need to create the icon.  For MS-Windows it must be in bitmap format,
 with the name "Compile.bmp".  For Unix XPM format is used, the file name is
index 45fe7de0878701cadffd046fef3f3adf266929dd..aadbf9b41925efdf81e598e9914688a414fb8d4b 100644 (file)
@@ -540,7 +540,7 @@ character (and shows it immediately).
 Added :wnext command.  Same as ":write" followed by ":next".
 
 The ":w!" command always writes, also when the file is write protected.  In Vi
-you would have to do ":!chmod +w %" and ":set noro".
+you would have to do ":!chmod +w %:S" and ":set noro".
 
 When 'tildeop' has been set, "~" is an operator (must be followed by a
 movement command).
index 3be3813b09c42a6d94a4c5ba1d3755dac3aef06d..85c40315458c260ae996f22b1f036bee4262990b 100644 (file)
@@ -16950,7 +16950,7 @@ f_shellescape(argvars, rettv)
     typval_T   *rettv;
 {
     rettv->vval.v_string = vim_strsave_shellescape(
-                      get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]));
+               get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), TRUE);
     rettv->v_type = VAR_STRING;
 }
 
@@ -24355,6 +24355,17 @@ repeat:
        }
     }
 
+    if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S')
+    {
+       p = vim_strsave_shellescape(*fnamep, FALSE, FALSE);
+       if (p == NULL)
+           return -1;
+       vim_free(*bufp);
+       *bufp = *fnamep = p;
+       *fnamelen = (int)STRLEN(p);
+       *usedlen += 2;
+    }
+
     return valid;
 }
 
index a9d7a82b0c49f35d8be312409c6b45bbce8102c9..8f8b2d9d462671fcd31a7426a185880afd8a2862 100644 (file)
@@ -1369,12 +1369,14 @@ csh_like_shell()
  * Escape a newline, depending on the 'shell' option.
  * When "do_special" is TRUE also replace "!", "%", "#" and things starting
  * with "<" like "<cfile>".
+ * When "do_newline" is FALSE do not escape newline unless it is csh shell.
  * Returns the result in allocated memory, NULL if we have run out.
  */
     char_u *
-vim_strsave_shellescape(string, do_special)
+vim_strsave_shellescape(string, do_special, do_newline)
     char_u     *string;
     int                do_special;
+    int                do_newline;
 {
     unsigned   length;
     char_u     *p;
@@ -1403,7 +1405,8 @@ vim_strsave_shellescape(string, do_special)
 # endif
        if (*p == '\'')
            length += 3;                /* ' => '\'' */
-       if (*p == '\n' || (*p == '!' && (csh_like || do_special)))
+       if ((*p == '\n' && (csh_like || do_newline))
+               || (*p == '!' && (csh_like || do_special)))
        {
            ++length;                   /* insert backslash */
            if (csh_like && do_special)
@@ -1454,7 +1457,8 @@ vim_strsave_shellescape(string, do_special)
                ++p;
                continue;
            }
-           if (*p == '\n' || (*p == '!' && (csh_like || do_special)))
+           if ((*p == '\n' && (csh_like || do_newline))
+                   || (*p == '!' && (csh_like || do_special)))
            {
                *d++ = '\\';
                if (csh_like && do_special)
index 73505a6c5df9ff7c506ef3885f694668bbe20721..b8c6fc24fd4246049c80a5e70ecb7e81c9cc3a70 100644 (file)
@@ -5790,7 +5790,7 @@ nv_ident(cap)
     {
        /* Escape the argument properly for a shell command */
        ptr = vim_strnsave(ptr, n);
-       p = vim_strsave_shellescape(ptr, TRUE);
+       p = vim_strsave_shellescape(ptr, TRUE, TRUE);
        vim_free(ptr);
        if (p == NULL)
        {
index 16c591831be69d816c79fb9a66a5c60b62ef85a7..544e669dcc7095e5f63d671c5ccd9a8c0dd32436 100644 (file)
@@ -32,7 +32,7 @@ char_u *vim_strnsave __ARGS((char_u *string, int len));
 char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
 char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
 int csh_like_shell __ARGS((void));
-char_u *vim_strsave_shellescape __ARGS((char_u *string, int do_special));
+char_u *vim_strsave_shellescape __ARGS((char_u *string, int do_special, int do_newline));
 char_u *vim_strsave_up __ARGS((char_u *string));
 char_u *vim_strnsave_up __ARGS((char_u *string, int len));
 void vim_strup __ARGS((char_u *p));
index e76ecb07d10b074d7cfbd787a544f802cce7fe10..d7f503f276fd8b58a0026c41cd7c38de2cb9bb69 100644 (file)
@@ -35,7 +35,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test89.out test90.out test91.out test92.out test93.out \
                test94.out test95.out test96.out test97.out test98.out \
                test99.out test100.out test101.out test102.out test103.out \
-               test104.out
+               test104.out test105.out
 
 .SUFFIXES: .in .out
 
@@ -156,3 +156,4 @@ test101.out: test101.in
 test102.out: test102.in
 test103.out: test103.in
 test104.out: test104.in
+test105.out: test105.in
index 58553598530d7e8376120e15559577666270be90..d26fe89638dd82a8d258202eb792d4b9836bfd87 100644 (file)
@@ -33,7 +33,8 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test84.out test85.out test86.out test87.out test88.out \
                test89.out test90.out test91.out test92.out test93.out \
                test94.out test95.out test96.out test98.out test99.out \
-               test100.out test101.out test102.out test103.out test104.out
+               test100.out test101.out test102.out test103.out test104.out \
+               test105.out
 
 SCRIPTS32 =    test50.out test70.out
 
index 4b9327977778579928f420d998adc1af2ccdb51d..0523ae48d4d12f67878e6e3188ddeefb522e45b3 100644 (file)
@@ -53,7 +53,8 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test84.out test85.out test86.out test87.out test88.out \
                test89.out test90.out test91.out test92.out test93.out \
                test94.out test95.out test96.out test98.out test99.out \
-               test100.out test101.out test102.out test103.out test104.out
+               test100.out test101.out test102.out test103.out test104.out \
+               test105.out
 
 SCRIPTS32 =    test50.out test70.out
 
index 7e37df70b14e693783090faf0e791f0bf6db6cf6..65c0946648c69bb3bd497bef5125b9e49fccfbf8 100644 (file)
@@ -35,7 +35,8 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test81.out test82.out test83.out test84.out test88.out \
                test89.out test90.out test91.out test92.out test93.out \
                test94.out test95.out test96.out test98.out test99.out \
-               test100.out test101.out test102.out test103.out test104.out
+               test100.out test101.out test102.out test103.out test104.out \
+               test105.out
 
 .SUFFIXES: .in .out
 
index f3483da437b54b1245f8903929ea2019b028fff6..de3fb485a01f4d01f12577448f2a4ee0fb7ac746 100644 (file)
@@ -4,7 +4,7 @@
 # Authors:     Zoltan Arpadffy, <arpadffy@polarhome.com>
 #              Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
 #
-# Last change:  2013 Nov 21
+# Last change:  2014 Feb 23
 #
 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
 # Edit the lines in the Configuration section below to select.
@@ -79,7 +79,8 @@ SCRIPT = test1.out  test2.out  test3.out  test4.out  test5.out  \
         test82.out test83.out test84.out test88.out test89.out \
         test90.out test91.out test92.out test93.out test94.out \
         test95.out test96.out test97.out test98.out test99.out \
-        test100.out test101.out test102.out test103.out test104.out
+        test100.out test101.out test102.out test103.out test104.out \
+        test105.out
 
 # Known problems:
 # Test 30: a problem around mac format - unknown reason
index bd298369c5a1ededd311d0a91c8ba62bb5e9e81e..d86a7b06e120243781e2cbb655579f38a3769525 100644 (file)
@@ -31,7 +31,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
                test89.out test90.out test91.out test92.out test93.out \
                test94.out test95.out test96.out test97.out test98.out \
                test99.out test100.out test101.out test102.out test103.out \
-               test104.out
+               test104.out test105.out
 
 SCRIPTS_GUI = test16.out
 
diff --git a/src/testdir/test105.in b/src/testdir/test105.in
new file mode 100644 (file)
index 0000000..284f3bf
--- /dev/null
@@ -0,0 +1,45 @@
+Test filename modifiers     vim: set ft=vim :
+
+STARTTEST
+:source small.vim
+:%delete _
+:set shell=sh
+:set shellslash
+:let tab="\t"
+:command -nargs=1 Put :let expr=<q-args> | $put =expr.tab.strtrans(string(eval(expr)))
+:let $HOME=fnamemodify('.', ':p:h:h:h')
+:Put fnamemodify('.',              ':p'      )[-1:]
+:Put fnamemodify('.',              ':p:h'    )[-1:]
+:Put fnamemodify('test.out',       ':p'      )[-1:]
+:Put fnamemodify('test.out',       ':.'      )
+:Put fnamemodify('../testdir/a',   ':.'      )
+:Put fnamemodify('test.out',       ':~'      )
+:Put fnamemodify('../testdir/a',   ':~'      )
+:Put fnamemodify('../testdir/a',   ':t'      )
+:Put fnamemodify('.',              ':p:t'    )
+:Put fnamemodify('test.out',       ':p:t'    )
+:Put fnamemodify('test.out',       ':p:e'    )
+:Put fnamemodify('test.out',       ':p:t:e'  )
+:Put fnamemodify('abc.fb2.tar.gz', ':r'      )
+:Put fnamemodify('abc.fb2.tar.gz', ':r:r'    )
+:Put fnamemodify('abc.fb2.tar.gz', ':r:r:r'  )
+:Put substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(src/testdir/.*\)', '\1', '')
+:Put fnamemodify('abc.fb2.tar.gz', ':e'      )
+:Put fnamemodify('abc.fb2.tar.gz', ':e:e'    )
+:Put fnamemodify('abc.fb2.tar.gz', ':e:e:e'  )
+:Put fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')
+:Put fnamemodify('abc.fb2.tar.gz', ':e:e:r'  )
+:Put fnamemodify('abc def',        ':S'      )
+:Put fnamemodify('abc" "def',      ':S'      )
+:Put fnamemodify('abc"%"def',      ':S'      )
+:Put fnamemodify('abc'' ''def',    ':S'      )
+:Put fnamemodify('abc''%''def',    ':S'      )
+:Put fnamemodify("abc\ndef",       ':S'      )
+:set shell=tcsh
+:Put fnamemodify("abc\ndef",       ':S'      )
+:$put ='vim: ts=8'
+:1 delete _
+:w! test.out
+:qa!
+ENDTEST
+
diff --git a/src/testdir/test105.ok b/src/testdir/test105.ok
new file mode 100644 (file)
index 0000000..0681597
--- /dev/null
@@ -0,0 +1,29 @@
+fnamemodify('.',              ':p'      )[-1:] '/'
+fnamemodify('.',              ':p:h'    )[-1:] 'r'
+fnamemodify('test.out',       ':p'      )[-1:] 't'
+fnamemodify('test.out',       ':.'      )      'test.out'
+fnamemodify('../testdir/a',   ':.'      )      'a'
+fnamemodify('test.out',       ':~'      )      '~/src/testdir/test.out'
+fnamemodify('../testdir/a',   ':~'      )      '~/src/testdir/a'
+fnamemodify('../testdir/a',   ':t'      )      'a'
+fnamemodify('.',              ':p:t'    )      ''
+fnamemodify('test.out',       ':p:t'    )      'test.out'
+fnamemodify('test.out',       ':p:e'    )      'out'
+fnamemodify('test.out',       ':p:t:e'  )      'out'
+fnamemodify('abc.fb2.tar.gz', ':r'      )      'abc.fb2.tar'
+fnamemodify('abc.fb2.tar.gz', ':r:r'    )      'abc.fb2'
+fnamemodify('abc.fb2.tar.gz', ':r:r:r'  )      'abc'
+substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(src/testdir/.*\)', '\1', '')  'src/testdir/abc.fb2'
+fnamemodify('abc.fb2.tar.gz', ':e'      )      'gz'
+fnamemodify('abc.fb2.tar.gz', ':e:e'    )      'tar.gz'
+fnamemodify('abc.fb2.tar.gz', ':e:e:e'  )      'fb2.tar.gz'
+fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')      'fb2.tar.gz'
+fnamemodify('abc.fb2.tar.gz', ':e:e:r'  )      'tar'
+fnamemodify('abc def',        ':S'      )      '''abc def'''
+fnamemodify('abc" "def',      ':S'      )      '''abc" "def'''
+fnamemodify('abc"%"def',      ':S'      )      '''abc"%"def'''
+fnamemodify('abc'' ''def',    ':S'      )      '''abc''\'''' ''\''''def'''
+fnamemodify('abc''%''def',    ':S'      )      '''abc''\''''%''\''''def'''
+fnamemodify("abc\ndef",       ':S'      )      '''abc^@def'''
+fnamemodify("abc\ndef",       ':S'      )      '''abc\^@def'''
+vim: ts=8
index 1459a3b48c7246151c66143cea23f9261929bb64..9c9586b1277d4aef7d12543cc7c41f318eb2c225 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    191,
 /**/
     190,
 /**/