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?
- X-seq: zsh-workers 48292
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Marlon Richert <marlon.richert@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Why does _main_complete not try the next completer when $_comp_mesg is non-zero?
- Date: Sun, 28 Mar 2021 13:51:12 -0700
- Archived-at: <https://zsh.org/workers/48292>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/CAH%2Bw%3D7Z3Cka8Mg7M0K%2BBsma0AUGpREXmaTEoVJhonuWcnVbfeQ%40mail.gmail.com>
- In-reply-to: <CAHLkEDvZ=hRKVXKjRpZsBCJ9DRm4wNEFpQ0EReHkgm7hGa-iTQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHLkEDt+5xiu62fLb2Gp9gQOh9Q_o8+-He64fooMMxPceon4vA@mail.gmail.com> <CAH+w=7bksUsvS6ixQ-zkCeYYf9+mrE4qz7CuVKW8CGuv=MAjOw@mail.gmail.com> <CAHLkEDvZ=hRKVXKjRpZsBCJ9DRm4wNEFpQ0EReHkgm7hGa-iTQ@mail.gmail.com>
On Sun, Mar 28, 2021 at 11:07 AM Marlon Richert
<marlon.richert@xxxxxxxxx> wrote:
>
> Would there be any drawback to removing this check?
I think it would break the intended behavior of "_guard" when used in
an _arguments action (which is how we're getting into _message in the
first place).
There is some divergence between the doc for _guard and the actual
implementation. The doc says:
_guard [ OPTIONS ] PATTERN DESCR
This function displays DESCR if PATTERN matches the string to be
completed. It is intended to be used in the ACTION for the
specifications passed to _arguments and similar functions.
The return status is zero if the message was displayed and the word
to complete is not empty, and non-zero otherwise.
In fact the return status only depends on the word being non-empty,
not on the message at all.
Another curiousity is that _message is supposed to take an optional tag
_message -e [ TAG ] DESCR
but _guard never passes it one, it just passes all it's non-option
arguments as a string:
_message -e "$*"
This has the effect that anything looked up as a style down-stack from
_message repeats the context as the tag, e.g. from _complete_debug:
+_description:15> zstyle -s
:completion::complete:grep:argument-1:argument-1 group-name gname
So there may very well be something more needed here than just
removing that check.
> Convenient would be that I could specify through a zstyle that I don't
> want that behavior. Though, why anyone would actually want the current
> behavior is unclear to me.
In this case the author of the _grep completion function determined
that to be the desirable behavior, otherwise _guard would not have
been used in that context.
Whether an author should ever be able to "know better" than the user
is an entirely different question. But there are tags generated for
both _guard and _message that could be used to look up additional
styles within those functions, if we as a group can agree on the
semantics.
Meanwhile, what about putting this in your completer style?
_complete_or_history () {
_complete "$@"
local ret=$? _mesg=$_comp_mesg
if [[ $ret -ne 0 || -n "$_comp_mesg" ]]
then
_comp_mesg=''
_history "$@" && ret=0
fi
(( $compstate[nmatches] )) || _comp_mesg=$mesg
return ret
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author