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

Re: compset -q oddities



Bart wrote:
> } That's a bit tricky.  I think it should append an escaped space, e.g.,
> } "sh -c touc<TAB>" should append <h> <Backslash> <Space>.
>
> No, that's *exactly* the kind of DWIM-ing that we abandoned.  If the user
> wants the space quoted, then he should start with "sh -c 'touc<TAB>".

For this specific case, I don't entirely agree because in theory the
mechanics are in place for that to work.

compset -q appears to disable the default suffix that completions have:
  _foo() {
    compset -q
    compadd one two three
  }
  foo "on<tab>  completes one without a space suffix.
I'm not sure why. Any ideas?

The other problem in this case is that suffixes are not quoted in
general. You're supposed to do that manually with compquote but we only
ever bother to do that in generic helpers. So the following does work as
Daniel wished:
  _foo() {
    suf=' '
    compquote suf
    compadd -S $suf one two three
  }          
  sh -c "foo on<tab>

You might even use ${compstate[quote]:#\\}$suf as the suffix to
close any inner quoting. -P prefixes and -S suffixes are added
unquoted: in contrast to -p/-s. This was probably done so that it
can include the closing quote. Either that or because that's how
compctl originally did things long before completion was complex
enough to worry much about quotes.

Adding calls to compquote in every function that needs a suffix is
not a good idea. With a code refactoring, perhaps the suffix could
be quoted automatically but we'd need an option that makes it easier
to indicate that quoting levels should be closed (accumulating them
as completion functions call each other). And I'm not sure about
prefixes.

In the past, I've looked at the compset code when noticing other odd
cases like those Daniel has mentioned. There's loads of edge cases that
are handled with bits of code that all dig into the parser code.
And the parser is not my favourite bit of zsh code either. Trying to fix
them just involves adding more hacks that are only making it worse. A
proper solution would need more flexible values in compqstack.

One other thing I notice in the code for compset -q is that it is
a completely different function internally from that which does the
initial word split when completion starts. I don't entirely understand
why because logically it ought to be possible to reuse the same
code. It'd be nice if vared could be used without the initial parse:
variable values aren't necessarily shell syntax.

Oliver



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