On 2014-03-11, Charles Campbell wrote:
> Ingo Karkat wrote:
> >On 11-Mar-2014 15:14 +0100, Ben Fritz wrote:
> >
> >><snip>
> >>Isn't this situation what shellescape() is designed for?
> >>
> >>That's not saying shellescape() will work, but I think it's supposed
> >>to work, unlike using a bare % which should always work for internal
> >>Vim commands but will only work by accident in external commands.
> >No, shellescape() would be used in a mapping / command, like this:
> >shellescape(expand('%'), 1). With the 1 flag (for use with :!), a
> >literal % is properly escaped to \% so that Vim's special handling does
> >not apply.
> >
> >% is handy for interactive use, like :!perl %
> >
> shellescape() is for use in a shell command argument being passed to
> the shell.  The documentation even shows an example of using a
> filter.
> fnameescape() is for internal-vim use involving filenames (ie. avoid
> having % have magic with exe when you don't want it to).
> %  is replaced with the current file name, just as it is typed. (see
> :he _%).

Not true.  Try this:

    :file foo\ bar()
    :!echo %

You will see the command as

    :!echo foo bar\(\)

> So, if the current filename contains spaces, that's what you can
> expect to see with the expansion.
> The right way to do what the OP wants:
> 
> :exe "w !diff ".shellescape(expand("%"))

That's certainly a workaround, but I wouldn't call it the "right
way".  For one thing, it's way too much to type when you just want
to run a shell command on the current file.  For another, there are
several examples in Vim's help (":helpgrep :!.*%") that show that %
is expected to "just work" in a shell command.  Further, as I just
discovered, this bug was reported twice previously and has this
comment in todo.txt:

    When the file name has parenthesis, e.g., "foo (bar).txt", ":!ls
    '%'" has the parenthesis escaped but not the space.  That's
    inconsistent.  Either escape neither or both.  No escaping might
    be best, because it doesn't depend on particularities of the
    shell. (Zvi Har'El, 2007 Nov 10) (Teemu Likonen, 2008 Jun 3)
    However, for backwards compatibility escaping might be
    necessary.  Check if the user put quotes around the expanded
    item?

Finally, it is clear from the code in ex_docmd.c that the intended
behavior of % in a shell command is for any special characters to be
escaped as % is expanded.

Granted, your proposed solution is a good one for the immediate
problem of that diff command, which I have bound to <F4> so I don't
really care what it looks like.  However, in this new age of people
using all sorts of wacky characters in file names, it would be nice
if either % or "%" just worked.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui