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

PATCH: compcontext



Here is the change to compcontext I promised. In short, one can set it 
to an array and the completion code will complete its elements. Or it
can be set to something containing colons, of the form
`<tag>:<descr>:<action>, giving the tag and description to use and the 
action is as for _arguments/_values.

Every other value is used as before (i.e. as a context name for lookup 
in _comps).

I hope this is not too complicated for the average user, but for the
simple cases they would probably just set it to an array and that is
definitely easy enough.

There are also some hunks in _arguments and _values to remove some
inconsistencies.


Bye
 Sven

Index: Completion/Base/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.28
diff -u -r1.28 _arguments
--- Completion/Base/_arguments	2000/07/26 08:44:13	1.28
+++ Completion/Base/_arguments	2000/08/01 07:12:00
@@ -270,8 +270,9 @@
 
               # Anything inside `(...)' is added directly.
 
-              _all_labels "$subc" expl "$descr" \
-                  compadd "$subopts[@]" - ${=action[2,-2]}
+              eval ws\=\( "${action[2,-2]}" \)
+
+              _all_labels "$subc" expl "$descr" compadd "$subopts[@]" -a - ws
 	      tried=yes
             elif [[ "$action" = \{*\} ]]; then
 
@@ -294,7 +295,7 @@
 
               # Otherwise we call it with the description-arguments.
 
-              set -A action ${=~action}
+	      eval "action=( $action )"
               while _next_label "$subc" expl "$descr"; do
                 "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}"
 	      done
Index: Completion/Base/_values
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_values,v
retrieving revision 1.4
diff -u -r1.4 _values
--- Completion/Base/_values	2000/04/11 07:57:56	1.4
+++ Completion/Base/_values	2000/08/01 07:12:00
@@ -119,8 +119,9 @@
 
       # Anything inside `(...)' is added directly.
 
-      _all_labels arguments expl "$descr" \
-          compadd "$subopts[@]" - ${=action[2,-2]}
+      eval ws\=\( "${action[2,-2]}" \)
+
+      _all_labels arguments expl "$descr" compadd "$subopts[@]" -a - ws
     elif [[ "$action" = \{*\} ]]; then
 
       # A string in braces is evaluated.
Index: Completion/Core/_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_complete,v
retrieving revision 1.6
diff -u -r1.6 _complete
--- Completion/Core/_complete	2000/06/29 08:20:32	1.6
+++ Completion/Core/_complete	2000/08/01 07:12:00
@@ -12,10 +12,70 @@
 # If we have a user-supplied context name, use only that.
 
 if [[ -n "$compcontext" ]]; then
-  ccarray[3]="$compcontext"
 
-  comp="$_comps[$compcontext]"
-  [[ -z "$comp" ]] || "$comp"
+  if [[ "${(t)compcontext}" = *(array|assoc)* ]]; then
+    local expl
+
+    _wanted values expl value compadd -a - compcontext
+
+  elif [[ "$compcontext" = *:*:* ]]; then
+    local tag="${${compcontext%%:*}:-values}"
+    local descr="${${${compcontext#${tag}:}%%:*}:-value}"
+    local action="${compcontext#${tag}:${descr}:}" expl ws ret=1
+
+    case "$action" in
+    \ #)
+      _message "$descr";;
+
+    \(\(*\)\))
+      eval ws\=\( "${action[3,-3]}" \)
+
+      _describe -t "$tag" "$descr" ws;;
+
+    \(*\))
+      eval ws\=\( "${action[2,-2]}" \)
+
+      _wanted "$tag" expl "$descr" compadd -a - ws;;
+
+    \{*\})
+      _tags "$tag"
+      while _tags; do
+        while _next_label "$tag" expl "$descr"; do
+          eval "$action[2,-2]" && ret=0
+	done
+	(( ret )) || break
+      done;;
+
+    \ *)
+      eval ws\=\( "$action" \)
+
+      _tags "$tag"
+      while _tags; do
+        while _next_label "$tag" expl "$descr"; do
+          "$ws[@]"
+	done
+	(( ret )) || break
+      done;;
+
+    *)
+      eval ws\=\( "$action" \)
+
+      _tags "$tag"
+      while _tags; do
+        while _next_label "$tag" expl "$descr"; do
+          "$ws[1]" "$expl[@]" "${(@)ws[2,-1]}"
+	done
+	(( ret )) || break
+      done;;
+
+    esac
+
+  else
+    ccarray[3]="$compcontext"
+
+    comp="$_comps[$compcontext]"
+    [[ -z "$comp" ]] || "$comp"
+  fi
 
   return
 fi
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.87
diff -u -r1.87 compsys.yo
--- Doc/Zsh/compsys.yo	2000/07/31 08:06:37	1.87
+++ Doc/Zsh/compsys.yo	2000/08/01 07:12:01
@@ -2313,13 +2313,21 @@
 named `tt(_tilde)').
 
 Before trying to find a function for a specific context, tt(_complete) 
-checks if the parameter `tt(compcontext)' is set to a non-empty
-value.  If it is, the value is taken as the name of the context to use
-and the function defined for that context will be called.  For this
-purpose, there is a special context named tt(-command-line-) that
-completes whole command lines (commands and their arguments) and is
-not used by the completion system itself, but has a function handling
-completion for it.
+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
+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.
+
+Finally, if `tt(compcontext)' is set a string without colons, the
+value is taken as the name of the context to use and the function
+defined for that context will be called.  For this purpose, there is a
+special context named tt(-command-line-) that completes whole command
+lines (commands and their arguments) and is not used by the completion
+system itself, but has a function handling completion for it.
 )
 findex(_correct)
 item(tt(_correct))(

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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