On 2009-02-03 09:28 (+1100), John Beckett wrote:
> Teemu Likonen:
> Are you reading this? Please help fix your tip!
I'm here. :-)
> More problems: As Charles said, the escape() is going to cause grief.
> I just looked through all the posts on the git mailing list (see the
> discussion on the proposed new tips page, via link at top of tip).
> They don't seem to think % is a problem, but have various other
> suggestions.
>
> I don't have time to fix all the new tips that people drop on the Vim
> Tips wiki. If we can't get this working before March, I'm going to
> suggest it gets removed. If anyone discovers something, please let us
> know.
This can't really be fixed. % and # are supposed to be expanded when
user executes the command line. These characters are being escape()d in
the script so that they don't get expanded twice. Otherwise even already
backslash-escaped % (for example, ":Shell echo \%") would be expanded
(and when % expands to filename with % character). That's because the
"execute" command will again run "!" command and the command line is
expanded again.
The actual problem is complicated. Try this example:
command! -complete=file -nargs=* Test ThisCommandDoesntExist
Now command ":Test %" gives that E499 error when executed in a buffer
with no filename. It never even tries to execute the non-existing
command. If we remove the -complete=file option then the command will be
executed and % and # are not expanded when user executes the command
line.
In theory those Vim meta characters could be expanded in the
s:RunShellCommand() function when it runs "!" command with "execute".
The problem is now that % and # are expanded in the context of the
scratch buffer and hence % doesn't actually point to anything useful. So
we want to keep the expand(a:cmdline,'%#') in the script untouched.
I'll conclude that we can have a sort of fix to this but we lose
filename completion and we lose % and # expansion. They are too useful
to me so I'm not going to change the version of the script on my
computer but for the Vim tip page the fix would be to remove the
-complete=file option:
command! -nargs=+ Shell call s:RunShellCommand(<q-args>)
And we need to remove the examples with % expansion.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---