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

Re: Setting the 'completer' style - _match and **

[ Your MUA seems to have changed the subject: your email has a hyphen
where the email you reply to had an em dash. ]

Bart Schaefer wrote on Mon, Sep 19, 2016 at 07:45:15 -0700:
> On Sep 12, 11:30pm, Daniel Shahaf wrote:
> } 
> } I've come up with the following:
> } .
> }     bindkey $'\t' complete-word
> }     zstyle ':completion:*' completer _all_matches _match-ds _expand _complete _ignored
> }     _match-ds() {
> }       [[ $PREFIX$SUFFIX != *[*][*]* ]] && _match "$@"
> }     }
> } .
> } The idea is that if a pattern contains "**" then _match('s wrapper) will
> } leave it for _expand to process.
> } 
> } Is there another way to implement this?
> You could probably come up with a "zstyle -e" formulation that would only
> include_match in the completer value in the right circurmstances.

How would I do that?  I think the "right circumstances" are [[ $curtag
== *(file|dir)* ]], but the 'completer' style is looked up under the
context :completion:::::, before tags are known.

I tried to workaround that by defining a compadd() wrapper function that
checks $curtag before calling the builtin compadd, but that caused
«: **/generic*<TAB>» to complete nothing.

> I'll note in passing that _match is supposed to be used after _complete,

The documentation says so too, but gives no rationale, and empirically
it works before _complete too.  Why should _match be later than _complete?

> not before _expand. Might it be better to suppress the _expand completer
> in the cases where you want _match rather than the other way around?

Perhaps I could do something like this:
    _match-ds2() {
        _match "$@"
        if that added no matches; then
          _expand "$@"
where the condition is implemented using $? or $compstate[nmatches], and
remove _expand from the 'completer' style entirely.  I'll give this
a shot later.

I want _match basically everywhere; when I want _expand I can invoke it
directly with ^X* <expand-word>.  I even use _match as
    rsync -[ap]<TAB>
to get the description of the -p option without getting a screenful of
other options.

Thanks for the answer,


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