about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Completion/Base/Completer/_complete10
-rw-r--r--Completion/Base/Core/_normal6
-rw-r--r--Completion/Base/Utility/_contexts10
-rw-r--r--Completion/Unix/Command/_su6
-rw-r--r--Doc/Zsh/compsys.yo15
6 files changed, 40 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 9247e3345..afa231754 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-01-21  Sven Wischnowsky  <wischnow@zsh.org>
+
+	* 16472: Completion/Base/Completer/_complete,
+	Completion/Base/Core/_normal, Completion/Base/Utility/_contexts,
+	Completion/Unix/Command/_su, Doc/Zsh/compsys.yo: allow
+	arguments to be given to functions used by compdef (actually,
+	the strings are eval'uated, so this should be powerful enough)
+
 2002-01-17  Oliver Kiddle  <opk@zsh.org>
 
 	* 16464: Completion/Base/Widget/_complete_debug,
diff --git a/Completion/Base/Completer/_complete b/Completion/Base/Completer/_complete
index 28bb008ca..98d293175 100644
--- a/Completion/Base/Completer/_complete
+++ b/Completion/Base/Completer/_complete
@@ -85,7 +85,7 @@ if [[ -n "$compcontext" ]]; then
     ccarray[3]="$compcontext"
 
     comp="$_comps[$compcontext]"
-    [[ -z "$comp" ]] || "$comp"
+    [[ -n "$comp" ]] && eval "$comp"
   fi
 
   return
@@ -94,10 +94,10 @@ fi
 # An entry for `-first-' is the replacement for `compctl -T'
 
 comp="$_comps[-first-]"
-if [[ ! -z "$comp" ]]; then
+if [[ -n "$comp" ]]; then
   service="${_services[-first-]:--first-}"
   ccarray[3]=-first-
-  "$comp" && ret=0
+  eval "$comp" && ret=0
   if [[ "$_compskip" = all ]]; then
     _compskip=
     return ret
@@ -135,8 +135,8 @@ else
     fi
     comp="$_comps[-default-]"
   fi
-  [[ -z "$comp" ]] ||
-      service="${_services[-default-]:--default-}" && "$comp" && ret=0
+  [[ -n "$comp" ]] &&
+      service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
 fi
 
 _compskip=
diff --git a/Completion/Base/Core/_normal b/Completion/Base/Core/_normal
index 364a56764..9ddfab1cd 100644
--- a/Completion/Base/Core/_normal
+++ b/Completion/Base/Core/_normal
@@ -19,7 +19,7 @@ if [[ CURRENT -eq 1 ]]; then
   curcontext="${curcontext%:*:*}:-command-:"
 
   comp="$_comps[-command-]"
-  [[ -z "$comp" ]] || "$comp" && ret=0
+  [[ -n "$comp" ]] && eval "$comp" && ret=0
 
   return ret
 else
@@ -86,7 +86,7 @@ service="${_services[$cmd1]:-$cmd1}"
 
 if [[ -n "$comp" ]]; then
   _compskip=patterns
-  "$comp" && ret=0
+  eval "$comp" && ret=0
   [[ "$_compskip" = (all|*patterns*) ]] && return ret
 elif [[ "$_compskip" != *default* ]]; then
   name=-default-
@@ -121,7 +121,7 @@ if [[ "$_compskip" != (all|*patterns*) ]]; then
 fi
 
 [[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] &&
-  service="${_services[-default-]:--default-}" && "$comp" && ret=0
+  service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
 
 _compskip=''
 
diff --git a/Completion/Base/Utility/_contexts b/Completion/Base/Utility/_contexts
index 680f2019f..f0e5ba874 100644
--- a/Completion/Base/Utility/_contexts
+++ b/Completion/Base/Utility/_contexts
@@ -7,11 +7,17 @@
 # `_contexts -math-' to get the completions that would be generated for a
 # mathematical context.
 
-local i tmp ret=1 service
+local i tmp ret=1 service or
+
+if [[ $1 = -o ]]; then
+  or=yes
+  shift
+fi
 
 for i; do
   tmp="$_comps[$i]"
-  [[ -z "$tmp" ]] || service="${_services[$i]:-$i}" && "$tmp" && ret=0
+  [[ -n "$tmp" ]] && service="${_services[$i]:-$i}" && eval "$tmp" && ret=0
+  [[ -n "$or" && ret -eq 0 ]] && return 0
 done
 
 return ret
diff --git a/Completion/Unix/Command/_su b/Completion/Unix/Command/_su
index daf301555..d8ed17183 100644
--- a/Completion/Unix/Command/_su
+++ b/Completion/Unix/Command/_su
@@ -16,7 +16,5 @@ fi
 
 shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
 compset -n $base
-for name in $shell $shell:t -default-; do
-  comp="$_comps[$name]"
-  [[ -n "$comp" ]] && "$comp" && return
-done  
+
+_contexts -o $shell $shell:t -default-
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index d7bfaa824..e382c0601 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -270,6 +270,15 @@ with the tt(#compdef) tag and an argument of the form
 `var(cmd)tt(=)var(service)'.  This kind of use makes the arguments of
 the var(cmd)s be completed as those for the var(services).
 
+In the first case and the following cases the var(function) may actually
+be a string containing any shell code and that string will be executed
+via the tt(eval) builtin command.  This allows to easily define completions
+for commands that need to call one of the completion functions with
+arguments.  For example to make files ending in `tt(.h)' be completed as
+arguments to the command tt(foo), one would use:
+
+example(compdef '_files -g "*.h"' foo)
+
 If the
 tt(-n) option is given, any existing completion behaviour for particular
 contexts or commands will not be altered.  These definitions can be deleted
@@ -3518,13 +3527,17 @@ tt(compadd) when generating matches from the style value, or to
 the functions for the fields if they are called.
 )
 findex(_contexts)
-item(tt(_contexts) var(names) ...)(
+item(tt(_contexts) [ tt(-o) ] var(names) ...)(
 This function looks up the definitions for the context and command
 names given as arguments and calls the handler functions for them if
 there is a definition (given with the tt(compdef) function).  For
 example, the function completing inside subscripts might use
 `tt(_contexts -math-)' to include the completions generated for
 mathematical environments.
+
+If the tt(-o) option is given, tt(_contexts) returns after the first
+context for which completions could be generated, without trying the
+other contexts.
 )
 findex(_describe)
 item(tt(_describe) [ tt(-o) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)(