zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/3] Make a helper function global.
@ 2016-10-16 17:14 Daniel Shahaf
  2016-10-16 17:14 ` [PATCH 2/3] _zstyle: When completing a style for an unrecognised context, complete all known styles Daniel Shahaf
  2016-10-16 17:14 ` [PATCH 3/3] _zstyle: Complete the -g, -s,-b,-a, -t,-T, -m options Daniel Shahaf
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Shahaf @ 2016-10-16 17:14 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/Zsh/Command/_zstyle  | 16 ----------------
 Completion/Zsh/Type/_completers | 14 ++++++++++++++
 Doc/Zsh/compsys.yo              | 10 ++++++++++
 3 files changed, 24 insertions(+), 16 deletions(-)
 create mode 100644 Completion/Zsh/Type/_completers

diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index 20ff47f..dcebc6f 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -4,22 +4,6 @@ local state context ostate line expl ctop suf
 local nm=$compstate[nmatches] taglist patterns pstyles contexts
 typeset -A opt_args styles
 
-(( $+functions[_completers] )) ||
-_completers() {
-  # option: -p - needs a `_' prefix
-  local us
-  local -a disp list expl
-
-  list=( complete approximate correct match expand list menu oldlist
-         ignored prefix history )
-  zparseopts -D -K -E 'p=us'
-  [[ -n "$us" ]] && us='_'
-  zstyle -t ":completion:${curcontext}:completers" prefix-hidden &&
-      disp=(-d list)
-  _wanted completers expl 'completer' \
-      compadd "$@" "$disp[@]" - "$us${^list[@]}"
-}
-
 _vcs_info_hooks() {
   compadd - ${functions[(I)+vi-*]#+vi-}
 }
diff --git a/Completion/Zsh/Type/_completers b/Completion/Zsh/Type/_completers
new file mode 100644
index 0000000..87c986a
--- /dev/null
+++ b/Completion/Zsh/Type/_completers
@@ -0,0 +1,14 @@
+#autoload
+
+# option: -p - needs a `_' prefix
+local us
+local -a disp list expl
+
+list=( complete approximate correct match expand list menu oldlist
+       ignored prefix history )
+zparseopts -D -K -E 'p=us'
+[[ -n "$us" ]] && us='_'
+zstyle -t ":completion:${curcontext}:completers" prefix-hidden &&
+    disp=(-d list)
+_wanted completers expl 'completer' \
+    compadd "$@" "$disp[@]" - "$us${^list[@]}"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 260ace4..a56ca67 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -4246,6 +4246,16 @@ This function completes words that are valid at command position: names of
 aliases, builtins, hashed commands, functions, and so on.  With the tt(-e)
 flag, only hashed commands are completed.  The tt(-) flag is ignored.
 )
+findex(_completers)
+item(tt(_completers) [ tt(-p) ])(
+This function completes names of completers.
+
+startitem()
+item(tt(-p))(
+Include the leading underscore (`tt(_)') in the matches.
+)
+enditem()
+)
 findex(_describe)
 redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ @ @ @ @ ))ifnztexi(          )))
 xitem(tt(_describe )[tt(-12JVx)] [ tt(-oO) | tt(-t) var(tag) ] var(descr) var(name1) [ var(name2) ] [ var(opt) ... ])


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] _zstyle: When completing a style for an unrecognised context, complete all known styles.
  2016-10-16 17:14 [PATCH 1/3] Make a helper function global Daniel Shahaf
@ 2016-10-16 17:14 ` Daniel Shahaf
  2016-10-16 17:14 ` [PATCH 3/3] _zstyle: Complete the -g, -s,-b,-a, -t,-T, -m options Daniel Shahaf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2016-10-16 17:14 UTC (permalink / raw)
  To: zsh-workers

Previously, vcs_info styles weren't completed.
---
 Completion/Zsh/Command/_zstyle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index dcebc6f..553917b 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -284,7 +284,7 @@ while (( $#state )); do
 	;;
 
 	(*)
-        ctop=cdez
+        ctop=a-z
 	;;
       esac
       _wanted styles expl style \


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 3/3] _zstyle: Complete the -g, -s,-b,-a, -t,-T, -m options.
  2016-10-16 17:14 [PATCH 1/3] Make a helper function global Daniel Shahaf
  2016-10-16 17:14 ` [PATCH 2/3] _zstyle: When completing a style for an unrecognised context, complete all known styles Daniel Shahaf
@ 2016-10-16 17:14 ` Daniel Shahaf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2016-10-16 17:14 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/Zsh/Command/_zstyle | 89 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 80 insertions(+), 9 deletions(-)

diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index 553917b..d6f2852 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -1,7 +1,7 @@
 #compdef zstyle
 
 local state context ostate line expl ctop suf
-local nm=$compstate[nmatches] taglist patterns pstyles contexts
+local nm=$compstate[nmatches] taglist patterns contexts
 typeset -A opt_args styles
 
 _vcs_info_hooks() {
@@ -216,17 +216,27 @@ taglist=(
   email-address ${(k)functions[(I)_email-*]#_}
 )
 
+# Be careful with the context arguments here.  They like to masquerade.
 _arguments -C \
-  '(-)-L[output in form of zstyle commands]' \
-  '(: -)-d[delete style definitions]:context pattern:->patterns:*:styles:->pstyles' \
-  '(-)-e[value is evaluated when style is looked up]' \
-  ':context:->contexts' ':style:->styles' '*:argument:->style-arg'
+  '(: -)-L[output in form of zstyle commands]:pattern for context patterns:->metapatterns:style:->metastyles' \
+  '(: -)-d[delete style definitions]:verbatim context pattern:->patterns:*:styles:->pstyles' \
+  '(: -)-e[value is evaluated when style is looked up]:context pattern:->contexts:style:->styles:*:command:_cmdstring' \
+  '(: -)-g[retrieve style definition]:array parameter:_parameters -g "*array*":verbatim context pattern:->patterns:styles:->pstyles' \
+  '(: -)-s[retrieve style value as string]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*":separator: ' \
+  '(: -)-b[retrieve style value as boolean]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*"' \
+  '(: -)-a[retrieve style value as array]:context name:->contexts:style:->styles:array parameter:_parameters -g "*array*"' \
+  '(: -)-t[test a style, returning false if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \
+  '(: -)-T[test a style, returning true if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \
+  '(: -)-m[pattern-match values of a style]:context name:->contexts:style:->styles:pattern: ' \
+  '(-):context pattern:->contexts' '(-):style:->styles' '(-)*:argument:->style-arg'
 
 while (( $#state )); do
   case "$state[1]" in
+    # 'contexts' completes either full context names (for -t/-s/-a), or context
+    # patterns (for 'zstyle :foo bar' and -e).
     (contexts)
       if [[ ! -prefix :*: ]]; then
-	_wanted contexts expl context compadd -P : -qS : chpwd completion vcs_info zftp zle
+	_wanted contexts expl "$state_descr"  compadd -P : -qS : chpwd completion vcs_info zftp zle
       elif compset -P :completion:; then
         contexts=( functions _completers cmdorcont argument tag )
       elif compset -P :vcs_info:; then
@@ -250,19 +260,80 @@ while (( $#state )); do
       fi
       ;;
 
+    # 'patterns' completes context patterns that are set, for -d/-g.
     (patterns)
       zstyle -g patterns
-      _wanted contexts expl 'context pattern' compadd -a patterns
+      _wanted contexts expl "$state_descr" compadd -a patterns
       ;;
 
+    # 'metapatterns': patterns that are are matched not against contexts, but
+    # against patterns.
+    (metapatterns)
+      zstyle -g patterns
+      patterns=( "${(@b)patterns}" )
+      _wanted contexts expl "$state_descr" compadd -a patterns
+      ;;
+
+    # 'metastyles': styles that are set on context patterns matching the given
+    # metapattern.
+    (metastyles)
+      # Anonymous function to shadow the global $styles assoc
+      () { 
+        local metapattern=${(Q)${${opt_args[-L]%:*}//(#m)\\([\\:])/${MATCH[2]}}}
+        local -a metastyles styles
+        local pattern
+        zstyle -g patterns
+        for pattern in "${(@M)patterns:#${~metapattern}}"; do
+          zstyle -g styles $pattern
+          metastyles+=( "${styles[@]}" )
+        done
+        _wanted styles expl "$state_descr" compadd -a metastyles
+        unset pattern
+        unset metastyles
+      }
+      ;;
+
+    # 'pstyles': complete styles that are set for the verbatim context pattern
+    # specified on the command line.  (If the user has set no zstyles, this
+    # will complete nothing.)
     (pstyles)
-      zstyle -g pstyles ${(Q)${(M)opt_args[-d]#*[^\\]:}%:}
+      local -a pstyles
+      local pattern
+      if (( $+opt_args[-d] )); then
+        pattern=${opt_args[-d]}
+        pattern=${pattern%":${(b)PREFIX}"} # remove style
+        pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping
+        pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob)
+        zstyle -g pstyles $pattern
+      elif (( $+opt_args[-g] )); then
+        pattern=${opt_args[-g]}
+        pattern=${pattern%":${(b)PREFIX}"} # remove style
+        pattern=${pattern#*:} # remove array name
+        pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping
+        pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob)
+        zstyle -g pstyles $pattern
+      fi
       _wanted styles expl style compadd -a pstyles
+      unset pattern
+      unset pstyles
     ;;
 
+    # 'styles': complete all styles that may be set in the context given on the
+    # command line.  This is independent of what styles are set.
     (styles)
       # Get the top-level context we're completing for, if any.
-      case ${(Q)line[1]} in
+      if [[ -n $line[1] ]]; then
+        # zstyle :something <TAB>
+        local the_context=$line[1]
+      else
+        # zstyle -x :something <TAB>
+        local joined_value=${(v)opt_args[(i)(-e|-s|-b|-a|-t|-T|-m)]}
+        local the_context=${(Q)joined_value[0, ${joined_value[(i)[^\\]:]}-2 ]}
+      fi
+      # Note: for 'zstyle :something <TAB>' and for 'zstyle -e :something <TAB>',
+      # $the_context is a context pattern; for -s,-b,-a,-t,-T,-m, it is a context
+      # name.  We currently draw no distinction between these two cases.
+      case $the_context in
 	(:completion:*)
 	ctop=c
 	;;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-16 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-16 17:14 [PATCH 1/3] Make a helper function global Daniel Shahaf
2016-10-16 17:14 ` [PATCH 2/3] _zstyle: When completing a style for an unrecognised context, complete all known styles Daniel Shahaf
2016-10-16 17:14 ` [PATCH 3/3] _zstyle: Complete the -g, -s,-b,-a, -t,-T, -m options Daniel Shahaf

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).