Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Why does _main_complete not try the next completer when $_comp_mesg is non-zero?
Marlon Richert wrote:
> The following line in _main_complete
>
> [[ -n "$_comp_mesg" ]] && break
>
> has the effect that, whenever _message has been called (with only few
> exceptions), the next completer won't be tried, _even when
> $compstate[nmatches] is zero._
>
> Why? What is the reason for this?
This allows you to see a hint of the command argument expected at the
cursor position. When you use commands that you're not especially
familiar with, getting prompts telling you what sort of value is
expected along with units and defaults can be very useful.
_messages -e/compadd -x was a later addition that allowed it to prompt
as-if there were matches which is useful for things like patterns and
numbers that can't be usefully completed. This also tied in with the
fake styles for adding fake matches.
I've always had a separate key bound for history completion.
> And is there a convenient way to work around this behavior? I want
> _history to be tried when _complete fails, but this behavior often
> prevents it. For example, if I try `grep \t`, then I get only the
> message `pattern`, whereas I would like to get history words.
You could create a wrapper for _complete that unsets it, something like:
_complete_nomesg() {
_complete
local ret=$?
_comp_mesg=
return ret
}
It might be better to experiment with something like that first. You'll
find that _message changing compstate[insert] is also affecting it.
> And if there is not an easy workaround, would you accept a patch from
> me that changes this?
That would break things that I've got too accustomed to over many years
so I'd not be enthusiastic about a patch that "changes this". Many
completion functions rely on the fact that they don't need to care so
much about return status if _message is called.
It could be possible to add some style or perhaps change the completer
style to allow for different criteria as to whether it continues. A
problem with trying to change this at the level of _main_complete is
that that is very generic and has no detailed information about the
context so any style lookup would be a basic on/off rather than being
context-sensitive.
If you want to experiment with it, guarding the first _comp_mesg
assignment in _message with [[ -n "$3" ]] && allows the format style to
be set to the empty string to disable the setting.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author