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?



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