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

compwhich



Would something like this be worthwhile? A function `compwhich',
currently just defined in `compinit' that gets names of command and
special contexts and spits out the functio names (and services) that
define their completion.


Bye
  Sven

diff -ur -r ../oz/Completion/compinit ./Completion/compinit
--- ../oz/Completion/compinit	Fri Jun 21 20:57:36 2002
+++ ./Completion/compinit	Fri Jun 21 21:32:27 2002
@@ -399,6 +399,59 @@
   fi
 }
 
+# A small function that prints the handling function(s) for its
+# arguments (names of commands or special contexts).
+
+compwhich()
+{
+eval "$_comp_setup"
+
+local _comp_command1 _comp_command2 _comp_command
+local i def strs str words
+
+strs=()
+for str; do
+  if [[ "$str" = -* ]] then
+    strs+=( "$str" )
+  else
+    words=($str)
+    _comp_command1=
+    _comp_command2=
+    _set_command
+    [[ -n "$_comp_command1" ]] && strs+=( "$_comp_command1" )
+    [[ -n "$_comp_command2" ]] && strs+=( "$_comp_command2" )
+  fi
+done
+
+_set_command
+
+for str in "$strs[@]"; do
+  def=yes
+
+  for i in "${(@)_patcomps[(K)$str]}"; do
+    print -r - "$str matches pre-pattern in $i${_services[$str]:+ (service: ${_services[$str]})}"
+    def=
+  done
+
+  if [[ -n "$def" ]]; then
+    i="${_comps[$str]}"
+    if [[ -n "$i" ]]; then
+      print -r - "$str is handled by $i${_services[$str]:+ (service: ${_services[$str]})}"
+      def=
+    fi
+  fi
+
+  if [[ -n "$def" ]]; then
+    for i in "${(@)_postpatcomps[(K)$str]}"; do
+      print -r - "$str matches post-pattern in $i${_services[$str]:+ (service: ${_services[$str]})}"
+      def=
+    done
+  fi
+
+  [[ -n "$def" ]] && print -r - "$str is handled by _default${_services[$str]:+ (service: ${_services[$str]})}"
+done
+}
+
 # Now we automatically make the definition files autoloaded.
 
 typeset _i_wdirs _i_wfiles
diff -ur -r ../oz/Doc/Zsh/compsys.yo ./Doc/Zsh/compsys.yo
--- ../oz/Doc/Zsh/compsys.yo	Fri Jun 21 20:57:35 2002
+++ ./Doc/Zsh/compsys.yo	Fri Jun 21 21:38:08 2002
@@ -252,7 +252,7 @@
 
 subsect(Functions)
 
-The tt(compinit) file defines the following function, which may
+The tt(compinit) file defines the following functions, which may
 also be called directly by the user.
 
 findex(compdef)
@@ -321,6 +321,15 @@
 In each of the forms supporting it the tt(-a) option makes the
 var(function) autoloadable (exactly equivalent to
 tt(autoload -U )var(function)).
+)
+
+findex(compwhich)
+cindex(completion system, searching definitions)
+startitem()
+item(tt(compwhich) var(names...))(
+This interprets each of the var(names) as the name of a command or
+special context, looks up which function(s) handle completion for them
+and prints their names.
 )
 enditem()
 

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



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