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

PATCH: compcontext again



Matthias sent me a mail answering an older message about
compcontext. That made me think of another easy-to-use things we can
do with it: if it is set to assoc, we can use the keys as the possible 
matches and the values as descriptions. That way round, because one
can the do:

  typeset -A compcontext
  compcontext=( foo 'describe foo'
                bar 'describe bar' ...)

Obviously.

The hunk in _arguments just changes the pattern to allow for the
optional `*' before the option name.

Bye
 Sven

Index: Completion/Base/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.31
diff -u -r1.31 _arguments
--- Completion/Base/_arguments	2000/08/02 09:09:56	1.31
+++ Completion/Base/_arguments	2000/08/02 10:32:04
@@ -78,7 +78,7 @@
 
       # Using (( ... )) gives a parse error.
 
-      let "$tmpargv[(I)(|\([^\)]#\))${opt}(|[-+=])(|\[*\])(|:*)]" ||
+      let "$tmpargv[(I)(|\([^\)]#\))(|\*)${opt}(|[-+=])(|\[*\])(|:*)]" ||
           tmp=( "$tmp[@]" "$opt" )
     done
     lopts=( "$tmp[@]" )
Index: Completion/Core/_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_complete,v
retrieving revision 1.7
diff -u -r1.7 _complete
--- Completion/Core/_complete	2000/08/01 07:19:15	1.7
+++ Completion/Core/_complete	2000/08/02 10:32:04
@@ -13,10 +13,21 @@
 
 if [[ -n "$compcontext" ]]; then
 
-  if [[ "${(t)compcontext}" = *(array|assoc)* ]]; then
+  if [[ "${(t)compcontext}" = *array* ]]; then
     local expl
 
     _wanted values expl value compadd -a - compcontext
+
+  elif [[ "${(t)compcontext}" = *assoc* ]]; then
+    local expl tmp i
+
+    tmp=()
+    for i in "${(@k)compcontext[(R)*[^[:blank:]]]}"; do
+      tmp=( "$tmp[@]" "${i}:${compcontext[$i]}" )
+    done
+    tmp=( "$tmp[@]" "${(k@)compcontext[(R)[[:blank:]]#]}" )
+
+    _describe -t values value tmp
 
   elif [[ "$compcontext" = *:*:* ]]; then
     local tag="${${compcontext%%:*}:-values}"
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.88
diff -u -r1.88 compsys.yo
--- Doc/Zsh/compsys.yo	2000/08/01 07:19:16	1.88
+++ Doc/Zsh/compsys.yo	2000/08/02 10:32:06
@@ -2315,9 +2315,12 @@
 Before trying to find a function for a specific context, tt(_complete) 
 checks if the parameter `tt(compcontext)' is set.  If it is set to an
 array, the elements are taken to be the possible matches which will be
-completed using the tag `tt(values)' and the description `tt(value)'.
-If `tt(compcontext)' to a string containing colons, it should be of
-the form `var(tag)tt(:)var(descr)tt(:)var(action)'. In this case the
+completed using the tag `tt(values)' and the description
+`tt(value)'.   If it is set to an associative array, the keys are used
+as the possible completions and the values (if non-empty) are used as
+descriptions for the matches.  If `tt(compcontext)' is set to a string
+containing colons, it should be of
+the form `var(tag)tt(:)var(descr)tt(:)var(action)'.  In this case the
 var(tag) and var(descr) give the tag and description to use and the
 var(action) says what should be completed in one of the forms
 described for the tt(_arguments) utility function below.

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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