Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to get prefix with quotes in completion widgets?



Ebourne, Martin wrote:

> Hi,
> 
> How do I get access to a version of $PREFIX which includes the quotes within a completion widget?

Quoting in completion is (and always was) a *very* complicated matter,
because ultimately we just can't reproduce the original quoting in all
cases (e.g. we have f'oo<TAB> on the line and the completion code adds
foobar as a match -- and that's a simple example). So instead of
trying to be perfect the code tries to produce at least correct
results even if that means that some of the special quoting on the
line will be lost. Internally the code uses an unquoted form which is
turned into some kind of generically quoted form when listed or
inserted into the line. In most cases this means backslashes before
special characters. Then we added a bit of special treatment for
strings *starting* with single or double quotes to be able to preserve
at least these.

And these single or double quotes can be found in $compstate[quote]
and $compstate[all_quotes] (and $QIPREFIX, for a different purpose,
but usable anyway). However, this of course only works for correct
shell syntax on the line and in your example:

> ...
> 
> example insert ( 'foo', 'bar' )
>                         ^^^
>                         123

the whole `(...)' is reported to the completion code (from the lexer
invoked by it) as one string, with quotes inside it, not at the
beginning, so the completion code doesn't handle them specially.

So, to answer your question: in *this* case, with the probably not
intended interpretation of the command line which can't be changed in
the completion code, there is no way to find the quotes other than by
looking e.g. at $BUFFER and $CURSOR of $words[CURRENT] (the former two
are zle-parameters accessible read-only in the completion code).

But if the stuff you want to complete really looks different from what
you sent, there might be a way. And anyway I'd like to know in which
real-world case you need it, we might have other ideas to help you.

Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author