From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: widget completion
Date: Thu, 28 Jul 2016 00:27:34 +0200 [thread overview]
Message-ID: <83384.1469658454@hydra.kiddle.eu> (raw)
We've got quite a few functions that need to complete zle widgets so it
seems to warrant factoring out into an _widgets function. This at least
encapsulates the matching control.
Like _parameters and _files, this takes a -g option to glob match
against the values in $widgets.
Oliver
diff --git a/Completion/Zsh/Command/_bindkey b/Completion/Zsh/Command/_bindkey
index 4c4aeda..81ae699 100644
--- a/Completion/Zsh/Command/_bindkey
+++ b/Completion/Zsh/Command/_bindkey
@@ -27,14 +27,11 @@ _arguments -C -s -S \
'(-l -L -d -D -A -N -m -p -r *)-s[bind each in-string to each out-string]:*:key string' \
'(-e -v -a -M -l -L -d -D -A -N -m -p)-R[interpret in-strings as ranges]' \
'(-l -L -d -A -N -m -p -r -s):in-string' \
- '(-l -L -d -A -N -m -p -r -s)*::widgets:->widget' && ret=0
+ '(-l -L -d -A -N -m -p -r -s)*::widgets:_widgets' && ret=0
case $state in
keymap)
- _wanted -C -M keymaps expl keymap compadd -a keymaps && ret=0
- ;;
- widget)
- _wanted widgets expl widget compadd -M 'r:|-=* r:|=*' -k widgets && ret=0
+ _wanted keymaps expl keymap compadd -a keymaps && ret=0
;;
esac
diff --git a/Completion/Zsh/Command/_vared b/Completion/Zsh/Command/_vared
index 2bcc87b..aba6488 100644
--- a/Completion/Zsh/Command/_vared
+++ b/Completion/Zsh/Command/_vared
@@ -6,8 +6,8 @@ _arguments -s -A "-*" \
"-c[create parameter or change type]" \
'-p+[specify left prompt]:prompt' \
'-r+[specify right prompt]:right prompt' \
- '-i+[specify initialisation widget]:widget:compadd -M "r\:|-=* r\:|=*" -k widgets' \
- '-f+[specify finish widget]:widget:compadd -M "r\:|-=* r\:|=*" -k widgets' \
+ '-i+[specify initialisation widget]:widget:_widgets' \
+ '-f+[specify finish widget]:widget:_widgets' \
'-h[allow access to history]' \
'-e[exit on EOF (^D)]' \
'1:parameter spec:_vars'
diff --git a/Completion/Zsh/Command/_zle b/Completion/Zsh/Command/_zle
index 3ed3733..f189b8f 100644
--- a/Completion/Zsh/Command/_zle
+++ b/Completion/Zsh/Command/_zle
@@ -48,20 +48,20 @@ case "$state[1]" in
'(-)*:widget arguments: ' && ret=0
;;
(widget*)
- _wanted -C "$context[1]" widgets expl "${state_descr[1]:-widget}" compadd -k widgets && ret=0
+ _wanted -C "$context[1]" widgets expl "${state_descr[1]:-widget}" _widgets && ret=0
;&
(function)
[[ $state[1] != *function ]] || # Handle fall-through
_wanted -C "$context[1]" functions expl 'widget shell function' \
- compadd -k functions && ret=0
+ compadd -M 'r:|-=* r:|=*' -k functions && ret=0
;;
(comp-widget)
_wanted -C "$context[1]" widgets expl 'completion widget' \
- compadd -k "widgets[(R)(*:|)(.|)(${(j(|))compwids})(|:*)]" && ret=0
+ _widgets -g "(*:|)(.|)(${(j(|))compwids})(|:*)" && ret=0
;&
(builtin-comp-widget)
_wanted -C "$context[1]" widgets expl 'builtin completion widget' \
- compadd -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0
+ compadd -M 'r:|-=* r:|=*' -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0
;;
(redisplay)
_arguments -s -S '!-R' \
diff --git a/Completion/Zsh/Function/_add-zle-hook-widget b/Completion/Zsh/Function/_add-zle-hook-widget
index da65dd6..93954a2 100644
--- a/Completion/Zsh/Function/_add-zle-hook-widget
+++ b/Completion/Zsh/Function/_add-zle-hook-widget
@@ -4,7 +4,7 @@ _add-zle-hook-widget_types() {
local -a tmp
autoload -U add-zle-hook-widget
- add-zle-hook-widget -h > /dev/null # sets the zstyle
+ add-zle-hook-widget -h >&/dev/null # sets the zstyle
zstyle -g tmp zle-hook types
compadd "$@" -M 'L:|=zle-' -M 'r:|-=* r:|=*' -- zle-${^tmp}
@@ -16,8 +16,7 @@ _add-zle-hook-widget_widgets() {
zstyle -g tmp $line[1] widgets
_wanted widgets expl "installed hook" compadd -- ${tmp#<->:} && return 0
else
- local -a user_widgets=( ${(k)widgets[(R)user:*]} )
- _wanted widgets expl widget compadd -M 'r:|-=* r:|=*' -a user_widgets && return 0
+ _wanted widgets expl widget _widgets -g 'user:*' && return 0
fi
return 1
}
diff --git a/Completion/Zsh/Type/_widgets b/Completion/Zsh/Type/_widgets
new file mode 100644
index 0000000..fdab281
--- /dev/null
+++ b/Completion/Zsh/Type/_widgets
@@ -0,0 +1,9 @@
+#autoload
+
+local expl pattern
+
+pattern=( -g \* )
+zparseopts -D -K -E g:=pattern
+
+_description widgets expl widget
+compadd "$@" "$expl[@]" -M 'r:|-=* r:|=*' - "${(@k)widgets[(R)${pattern[2]}]}"
next reply other threads:[~2016-07-27 22:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-27 22:27 Oliver Kiddle [this message]
2016-07-28 18:12 ` Daniel Shahaf
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=83384.1469658454@hydra.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@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).