zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-users@zsh.org
Subject: Re: Setting the 'completer' style - _match and **
Date: Tue, 20 Sep 2016 08:54:31 +0000	[thread overview]
Message-ID: <20160920085431.GA3720@fujitsu.shahaf.local2> (raw)
In-Reply-To: <160919074515.ZM28018__10595.0927398682$1474296416$gmane$org@torch.brasslantern.com>

[ 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
          curcontext=${curcontext/:match-ds2:/expand}
          _expand "$@"
        fi
    }
.
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,

Daniel


  parent reply	other threads:[~2016-09-20  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 23:30 Setting the 'completer' style — " Daniel Shahaf
2016-09-19 14:45 ` Setting the 'completer' style - " Bart Schaefer
     [not found] ` <160919074515.ZM28018__10595.0927398682$1474296416$gmane$org@torch.brasslantern.com>
2016-09-20  8:54   ` Daniel Shahaf [this message]
2016-09-20 15:46     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160920085431.GA3720@fujitsu.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).