summaryrefslogtreecommitdiff
path: root/Completion/Core/compdump
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Core/compdump')
-rw-r--r--Completion/Core/compdump62
1 files changed, 43 insertions, 19 deletions
diff --git a/Completion/Core/compdump b/Completion/Core/compdump
index 8be096f50..3cccbd06e 100644
--- a/Completion/Core/compdump
+++ b/Completion/Core/compdump
@@ -1,4 +1,4 @@
-# This is a file to be sourced to dump the definitions for new-style
+# 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
@@ -9,33 +9,46 @@
# 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.
-#
-# It relies on KSH_ARRAYS not being set.
# Print the number of files used for completion. This is used in compinit
# to see if auto-dump should re-dump the dump-file.
-_d_file=${COMPDUMP-${0:h}/compinit.dump}
+emulate -L zsh
+setopt extendedglob
+
+typeset _d_file _d_f _d_bks _d_line _d_als
+
+_d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$
typeset -U _d_files
-_d_files=( ${^~fpath}/_*~*~(N:t) )
+_d_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N:t) )
print "#files: $#_d_files" > $_d_file
-unset _d_files
-
# First dump the arrays _comps and _patcomps. The quoting hieroglyphyics
# 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 - "'${_d_f//\'/'\\''}'" "'${_comps[$_d_f]//\'/'\\''}'"
+ print -r - "${(q)_d_f}" "${(q)_comps[$_d_f]}"
done >> $_d_file
print ")" >> $_d_file
print "\n_patcomps=(" >> $_d_file
-for _d_f in "$_patcomps[@]"; do
- print -r - "'${_d_f//\'/'\\''}'"
+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
@@ -44,11 +57,13 @@ 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=()
zle -lL |
while read -rA _d_line; do
- if [[ ${_d_line[5]} = _* ]]; then
+ if [[ ${_d_line[3]} = _* && ${_d_line[5]} = _* ]]; then
print -r - ${_d_line}
_d_bks=($_d_bks ${_d_line[3]})
fi
@@ -73,17 +88,26 @@ done))
# print them out: about five to a line looks neat
+_i=5
+print -n autoload -U >> $_d_file
while (( $#_d_als )); do
- print -n autoload
- for (( _i = 0; _i < 5; _i++ )); do
- if (( $#_d_als )); then
- print -n " $_d_als[1]"
- shift _d_als
+ if (( ! $+_compautos[$_d_als[1]] )); then
+ print -n " $_d_als[1]"
+ if (( _i-- && $#_d_als > 1 )); then
+ _i=5
+ print -n '\nautoload -U'
fi
- done
- print
+ fi
+ shift _d_als
done >> $_d_file
print >> $_d_file
-unset _d_line _d_zle _d_bks _d_als _d_f _f_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