about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2002-06-23 04:53:00 +0000
committerBart Schaefer <barts@users.sourceforge.net>2002-06-23 04:53:00 +0000
commitaf04d02643b8203c9804387958abdcd4d5ba8fcb (patch)
treeca972e38675070bfa28f0287c64ae3a2c630cad6
parent7b0d0759b3fd93e6d420e6387bf2fb89b4d04e9c (diff)
downloadzsh-af04d02643b8203c9804387958abdcd4d5ba8fcb.tar.gz
zsh-af04d02643b8203c9804387958abdcd4d5ba8fcb.tar.xz
zsh-af04d02643b8203c9804387958abdcd4d5ba8fcb.zip
users/5073: use typeset to get function names for compdump
-rw-r--r--ChangeLog5
-rw-r--r--Completion/compdump131
2 files changed, 136 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 3f0e70231..4a873c241 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-06-22  Bart Schaefer  <schaefer@zsh.org>
+
+	* users/5073: Completion/compdump: use `typeset +f' instead of
+	`whence -w' to get names of completion functions.
+
 2002-06-14  Peter Stephenson  <pws@csr.com>
 
 	* 17318: Src/hist.c: ${(z)...} appended an extra space when the
diff --git a/Completion/compdump b/Completion/compdump
new file mode 100644
index 000000000..e0316fb6a
--- /dev/null
+++ b/Completion/compdump
@@ -0,0 +1,131 @@
+# This is a function to dump the definitions for new-style
+# completion defined by 'compinit' in the same directory.  The output
+# should be directed into the "compinit.dump" in the same directory as
+# compinit. If you rename init, just stick .dump onto the end of whatever
+# you have called it and put it in the same directory.  This is handled
+# automatically if you invoke compinit with the option -d.
+#
+# You will need to update the dump every time you add a new completion.
+# To do this, simply remove the .dump file, start a new shell, and
+# create the .dump file as before.  Again, compinit -d handles this
+# automatically.
+
+# Print the number of files used for completion. This is used in compinit
+# to see if auto-dump should re-dump the dump-file.
+
+emulate -L zsh
+setopt extendedglob noshglob
+
+typeset _d_file _d_f _d_bks _d_line _d_als _d_files
+
+_d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$
+[[ $_d_file = //* ]] && _d_file=${_d_file[2,-1]}
+
+[[ -w ${_d_file:h} ]] || return 1
+
+_d_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N) )
+
+if [[ -n "$_comp_secure" ]]; then
+  _d_wdirs=( ${^fpath}(Nf:g+w:,f:o+w:,^u0u${EUID}) )
+  _d_wfiles=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N^u0u${EUID}) )
+
+  (( $#_d_wfiles )) && _d_files=( "${(@)_d_files:#(${(j:|:)_d_wfiles})}"  )
+  (( $#_d_wdirs ))  && _d_files=( "${(@)_d_files:#(${(j:|:)_d_wdirs})/*}" )
+fi
+
+print "#files: $#_d_files" > $_d_file
+
+# First dump the arrays _comps, _services and _patcomps.  The quoting
+# hieroglyphics ensure that a single quote inside a variable is itself
+# correctly quoted.
+
+print "_comps=(" >> $_d_file
+for _d_f in ${(ok)_comps}; do
+    print -r - "${(q)_d_f}" "${(q)_comps[$_d_f]}"
+done  >> $_d_file
+print ")" >> $_d_file
+
+print "_services=(" >> $_d_file
+for _d_f in ${(ok)_services}; do
+    print -r - "${(q)_d_f}" "${(q)_services[$_d_f]}"
+done  >> $_d_file
+print ")" >> $_d_file
+
+print "\n_patcomps=(" >> $_d_file
+for _d_f in "${(ok@)_patcomps}"; do
+  print -r - "${(q)_d_f}" "${(q)_patcomps[$_d_f]}"
+done >> $_d_file
+print ")" >> $_d_file
+
+print "\n_postpatcomps=(" >> $_d_file
+for _d_f in "${(ok@)_postpatcomps}"; do
+  print -r - "${(q)_d_f}" "${(q)_postpatcomps[$_d_f]}"
+done >> $_d_file
+print ")" >> $_d_file
+
+print "\n_compautos=(" >> $_d_file
+for _d_f in "${(ok@)_compautos}"; do
+  print -r - "${(q)_d_f}" "${(q)_compautos[$_d_f]}"
+done >> $_d_file
+print ")" >> $_d_file
+
+print >> $_d_file
+
+# Now dump the key bindings. We dump all bindings for zle widgets
+# whose names start with a underscore.
+# We need both the zle -C's and the bindkey's to recreate.
+# We can ignore any zle -C which rebinds a standard widget (second
+# argument to zle does not begin with a `_').
+
+_d_bks=()
+_d_complist=
+zle -lL |
+  while read -rA _d_line; do
+    if [[ ${_d_line[3]} = _* && ${_d_line[5]} = _* ]]; then
+      if [[ -z "$_d_complist" && ${_d_line[4]} = .menu-select ]]; then
+        print 'zmodload -i zsh/complist'
+	d_complist=yes
+      fi
+      print -r - ${_d_line}
+      _d_bks=($_d_bks ${_d_line[3]})
+    fi
+  done >> $_d_file
+bindkey |
+  while read -rA _d_line; do
+    if [[ ${_d_line[2]} = (${(j.|.)~_d_bks}) ]]; then
+      print -r "bindkey '${_d_line[1][2,-2]}' ${_d_line[2]}"
+    fi
+  done >> $_d_file
+
+print >> $_d_file
+
+
+# Autoloads: look for all functions beginning with `_'.
+
+_d_als=(${(o)$(typeset +fm '_*')})
+
+# print them out:  about five to a line looks neat
+
+_i=5
+print -n autoload -U >> $_d_file
+while (( $#_d_als )); do
+  if (( ! $+_compautos[$_d_als[1]] )); then
+    print -n " $_d_als[1]"
+    if (( ! --_i && $#_d_als > 1 )); then
+      _i=5
+      print -n ' \\\n           '
+    fi
+  fi
+  shift _d_als
+done >> $_d_file
+
+print >> $_d_file
+
+for _i in "${(ok@)_compautos}"; do
+  print "autoload -U $_compautos[$_i] $_i" >> $_d_file
+done
+
+mv $_d_file ${_d_file%.$HOST.$$}
+
+unfunction compdump
+autoload -U compdump