Comments inline...

On Apr 17, 11:55 pm, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
> On 18/04/11 04:23, Ted wrote:
...
> > I've written a command that will replace the contents of a buffer with
> > the output of a shell command.
>
> :%r !whatever
>
> or if the buffer contains the command's stdin (or if it reads no estdin)
>
> :%!whatever
>
> in both cases replacing "whatever" by the command
Well, it really does more than this: it saves the command in a buffer-
local variable so that calling `:RePut` with no arguments will refresh
it conveniently.  I like to use this if I'm doing syntax checking or
whatnot on a bunch of different files during the same editing session,
but there are other possible uses.  It also retains the cursor
position across the refresh.  Actually, the command works by invoking
a more general command (`:RePut`) that replaces the buffer contents
with the result of a vimscript expression, using `:PrettyPrint` if
available for Lists and Dictionaries.  `:RePutShell` splices its
quoted + string()ified arguments into a call to `system()` and then
invokes `:RePut` with the call as its arguments.  I suspect that the
name or at least the capitalization may suck; suggestions are welcome.

> well, on
>
>         :!ln -sv FILENAME LINKNAME
>
> I get completion for the fileName. Haven't tried it on the linkname.
Yeah, I'm just guessing, really.  Any time that I've noticed what it's
providing for arguments after the command name, it's providing file
paths.  `:help *cmdline-completion*` doesn't seem to cover this
detail.  I guess I could source-dive to find out.

Replicating such behaviour manually is not really hard: I can just use
vim's glob() function (I think).  The tricky part here seems to be
splitting the typed command into args.  Getting the escaping and
unescaping right might be a bit complicated, too.  Mostly I'm hoping
that someone's already done this and made their code available as an
addon, or that some feature of vim makes such travails unnecessary.

> If you want bash to handle completion for your command, you'll have to
> call bash while typing the command, since IIRC completion can be
> customized in bash itself so that it can potentially act correctly on
> any possible command, including user-defined ones. But I don't think
> it's (easily) possible.
Yes, that's the basic idea.  I would write a custom completion
function that calls `system()` in such a way as to get a list of
completions for the partially-typed command arguments.  This involves
invoking bash and telling it to do .. something magical.  The tricky
bit is that bash doesn't seem to provide any way to programmatically
get a list of completions.  So if I do choose to go this route, it
looks like I either have to reproduce bash's behaviour in a sourced
bash script or find some way to fake a TAB keypress.  The latter would
I think require using `screen` or some other slime-y setup.

I think I've figured out how to get bash to generate completions given
a command (and partial arguments) whose completion is handled by a
bash function (as registered via `complete -F FUNCTION COMMAND`).  So
I may settle for doing this and just extending the results with file
paths optionally or if there are no completions or no registered
completion function.  I gather that this is more or less what bash
does, but its behaviour is governed by at least a couple of options,
some of which are specific to the completion itself.

-- 
You received this message from the "vim_use" 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

Reply via email to