* Setting the 'completer' style — _match and **
@ 2016-09-12 23:30 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>
0 siblings, 2 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-12 23:30 UTC (permalink / raw)
To: zsh-users
I'm trying to configure my zshrc such that:
1. The following —
.
% mkdir -p html/generic.5.html man/man5/generic.5
% : **/generic.*<TAB>
.
— offers both directories.
2. The following —
.
% mkdir nntp-gmane
% service *ntp*<TAB>
.
— offers "openntpd" but not "nntp-gmane".
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?
Cheers,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Setting the 'completer' style - _match and **
2016-09-12 23:30 Setting the 'completer' style — _match and ** Daniel Shahaf
@ 2016-09-19 14:45 ` Bart Schaefer
[not found] ` <160919074515.ZM28018__10595.0927398682$1474296416$gmane$org@torch.brasslantern.com>
1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-19 14:45 UTC (permalink / raw)
To: zsh-users
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. I'm not
sure that's a better solution than yours.
I'll note in passing that _match is supposed to be used after _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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Setting the 'completer' style - _match and **
[not found] ` <160919074515.ZM28018__10595.0927398682$1474296416$gmane$org@torch.brasslantern.com>
@ 2016-09-20 8:54 ` Daniel Shahaf
2016-09-20 15:46 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-20 8:54 UTC (permalink / raw)
To: zsh-users
[ 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Setting the 'completer' style - _match and **
2016-09-20 8:54 ` Daniel Shahaf
@ 2016-09-20 15:46 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-20 15:46 UTC (permalink / raw)
To: zsh-users
On Sep 20, 8:54am, Daniel Shahaf wrote:
}
} [ Your MUA seems to have changed the subject: your email has a hyphen
} where the email you reply to had an em dash. ]
Sorry about that; mail to my home desktop passes through a number of
gateways and processing steps, some of which think non-ascii subjects
are potential spam indicators.
} > } The idea is that if a pattern contains "**" then _match('s wrapper) will
} > } leave it for _expand to process.
} >
} > 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 was thinking quite literally what you said about the pattern:
zstyle -e ':completion:*' completer \
'[[ $PREFIX$SUFFIX == *[*][*]* ]] && reply=(... _expand ...) || \
reply=(... _match ...)'
But you could add to the [[ ]] e.g. "&& $words[1] == service" (the
value of $service hasn't been set yet there either because it's a
feature of _complete).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-20 15:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12 23:30 Setting the 'completer' style — _match and ** 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
2016-09-20 15:46 ` Bart Schaefer
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).