about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-07-03 13:16:46 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-07-03 13:16:46 +0000
commit7c670f1e6a0e154f0b1a2d4b6eed0e71c9404b56 (patch)
tree9bb85bcd27410e1b752c8550f487165d71dc8aca /Completion
parentb09922bb063ddf44c7850b182fec4795fbe1ae90 (diff)
downloadzsh-dot-zsh-199907031715.tar.gz
zsh-dot-zsh-199907031715.tar.xz
zsh-dot-zsh-199907031715.zip
zsh-3.1.5-pws-25 dot-zsh-199907031715
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/_first72
-rw-r--r--Completion/Base/_subscript19
-rw-r--r--Completion/Builtins/_cd4
-rw-r--r--Completion/Commands/.distfiles2
-rw-r--r--Completion/Commands/_expand_word26
-rw-r--r--Completion/Core/_expand3
-rw-r--r--Completion/Core/_path_files6
-rw-r--r--Completion/Core/compdump13
-rw-r--r--Completion/Core/compinit93
-rw-r--r--Completion/Core/compinstall107
-rw-r--r--Completion/User/_hosts6
11 files changed, 203 insertions, 148 deletions
diff --git a/Completion/Base/_first b/Completion/Base/_first
index 655e3569f..8b4da019d 100644
--- a/Completion/Base/_first
+++ b/Completion/Base/_first
@@ -1,11 +1,63 @@
-#compdef -subscript-
+#compdef -first-
 
-if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
-  if [[ "$RBUFFER" = \]* ]]; then
-    compadd -S '' - "${(@kP)${compstate[parameter]}}"
-  else
-    compadd -S ']' - "${(@kP)${compstate[parameter]}}"
-  fi
-else
-  _compalso -math-
-fi
+# This function is called at the very beginning before any other
+# function for a specific context.
+#
+# This just gives some examples of things you might want to do here.
+#
+#
+# If you use the vared builtin and want completion in there to act the 
+# way completion on the right hand side of assignments is done, add
+# (or un-comment) this code:
+#
+#     if [[ -n $compstate[vared] ]]; then
+#       if [[ $compstate[vared] = *\[* ]]; then
+#         # vared on an array-element
+#         compstate[parameter]=${compstate[vared]%%\[*}
+#         compstate[context]=value
+#       else
+#         # vared on a parameter, let's see if it is an array
+#         compstate[parameter]=$compstate[vared]
+#         if [[ ${(tP)compstate[vared]} = *(array|assoc)* ]]; then
+#           compstate[context]=array_value
+#         else
+#           compstate[context]=value
+#         fi
+#       fi
+#       return
+#     fi
+#
+#
+#
+# Other things you can do here is to complete different things if the
+# word on the line matches a certain pattern. This example allows
+# completion of words from the history by adding two commas at the end 
+# and hitting TAB.
+#
+#     if [[ "$PREFIX" = *,, ]]; then
+#       local max i=1
+#     
+#       PREFIX="$PREFIX[1,-2]"
+#       # If a numeric prefix is given, we use it as the number of
+#       # lines (multiplied by ten below) in the history to search.
+#       if [[ ${NUMERIC:-1} -gt 1 ]]; then
+#         max=$NUMERIC
+#         unset NUMERIC
+#       else
+#         # The default is to search the last 100 lines.
+#         max=10
+#       fi
+#       # We first search in the last ten lines, then in the last
+#       # twenty lines, and so on...
+#       while [[ i -le max ]]; do
+#         if compgen -X "%Bhistory ($n):%b" -Q -H $(( i*10 )) ''; then
+#           # We have found at least one matching word, so we switch
+#           # on menu-completion and make sure that no other
+#           # completion function is called by setting _comp_skip.
+#           compstate[insert]=menu
+#           _comp_skip=1
+#           return
+#         fi
+#         (( i++ ))
+#       done
+#     fi
diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript
index 00b2b6506..be5f08f62 100644
--- a/Completion/Base/_subscript
+++ b/Completion/Base/_subscript
@@ -1,6 +1,9 @@
 #compdef -subscript-
 
-if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
+if [[ "$PREFIX" = :* ]]; then
+  compadd -p: -S ':]' alnum alpha blank cntrl digit graph lower print punct \
+      space upper xdigit
+elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
   if [[ "$RBUFFER" = \]* ]]; then
     compadd -S '' - "${(@kP)${compstate[parameter]}}"
   else
@@ -13,15 +16,15 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
   list=()
   for i in "$ind[@]"; do
     [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
-        list=( "$list[@]" "${(r:4:: ::):)i} ${(P)${compstate[parameter]}[$i]}
-)
+        list=( "$list[@]" 
+	  "${(r:4:: ::):)i} $(print -D ${(P)${compstate[parameter]}[$i]})" )
   done
 
- if [[ "$RBUFFER" = \]* ]]; then
-   compadd -S '' -y list - "$ind[@]"
- else
-   compadd -S ']' -y list - "$ind[@]"
- fi
+  if [[ "$RBUFFER" = \]* ]]; then
+    compadd -S '' -V default -y list - "$ind[@]"
+  else
+    compadd -S ']' -V default -y list - "$ind[@]"
+  fi
 else
   _compalso -math-
 fi
diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd
index 61abd2068..4a846c6aa 100644
--- a/Completion/Builtins/_cd
+++ b/Completion/Builtins/_cd
@@ -5,7 +5,7 @@
 #    and the string doesn't begin with ~, /, ./ or ../.
 #  - In the second argument to cd for the form `cd old new', completes
 #    possible `new' strings by examining `old' and $PWD.
-#  - After pushd - or pushd +, completes numbers, but the listing
+#  - After - or +, completes numbers, but the listing
 #    gives you the list of directories to complete.  This turns on
 #    menu-completion and lists the possibilities automatically, otherwise
 #    it's not a lot of use.  If you don't type the + or - it will
@@ -25,7 +25,7 @@ if [[ CURRENT -eq 3 ]]; then
   # Now remove all the common parts of $PWD and the completions from this
   rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
   (( ! $#rep )) || compadd $rep
-elif [[ $words[1] = pu* && $PREFIX = [-+]* ]]; then
+elif [[ $PREFIX = [-+]* ]]; then
   # pushd: just complete the numbers, but show the full directory list with
   # numbers.
   # For - we do the same thing, but reverse the numbering (other
diff --git a/Completion/Commands/.distfiles b/Completion/Commands/.distfiles
index 19a02ef39..7b2a319fe 100644
--- a/Completion/Commands/.distfiles
+++ b/Completion/Commands/.distfiles
@@ -1,3 +1,3 @@
 DISTFILES_SRC='
-    .distfiles _correct_filename _correct_word _most_recent_file 
+    .distfiles _correct_filename _correct_word _expand_word _most_recent_file 
 '
diff --git a/Completion/Commands/_expand_word b/Completion/Commands/_expand_word
new file mode 100644
index 000000000..570f06987
--- /dev/null
+++ b/Completion/Commands/_expand_word
@@ -0,0 +1,26 @@
+#compdef -k complete-word \C-xe
+
+# Simple completion front-end implementing expansion.
+#
+# If configurations keys with the prefix `expandword_' are
+# given they override those starting with `expand_'.
+
+local oes="$compconfig[expand_substitute]"
+local oeg="$compconfig[expand_glob]"
+local oem="$compconfig[expand_menu]"
+local oeo="$compconfig[expand_original]"
+local oep="$compconfig[expand_prompt]"
+
+compconfig[expand_substitute]="${compconfig[expandword_substitute]}"
+compconfig[expand_glob]="${compconfig[expandword_glob]-$oeg}"
+compconfig[expand_menu]="${compconfig[expandword_menu]-$oem}"
+compconfig[expand_original]="${compconfig[expandword_original]-$oeo}"
+compconfig[expand_prompt]="${compconfig[expandword_prompt]-$oep}"
+
+_main_complete _expand
+
+compconfig[expand_substitute]="$oes"
+compconfig[expand_glob]="$oeg"
+compconfig[expand_menu]="$oem"
+compconfig[expand_original]="$oeo"
+compconfig[expand_prompt]="$oep"
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index 58e184657..778293a8b 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -57,7 +57,6 @@
 #    `%o' in this string will be replaced by the original string.
 
 local exp word="$PREFIX$SUFFIX" group=-V
-
 # Do this only for the first global matcher.
 
 [[ "$compstate[matcher]" -le 1 ]] || return 1
@@ -88,7 +87,7 @@ exp=("$word")
 # as the original string, we let other completers run.
 
 [[ $#exp -eq 0 ||
-   ( $#exp -eq 1 && "$exp[1]" = "$word" ) ]] && return 1
+   ( $#exp -eq 1 && "$exp[1]" = "$word"(|\(N\)) ) ]] && return 1
 
 # We have expansions, should we menucomplete them?
 
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 77365a01a..58f343367 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -377,9 +377,9 @@ done
 exppaths=( "${(@)exppaths:#$orig}" )
 
 if [[ -n "$compconfig[path_expand]" &&
-      $#exppaths -ne 0 && nm -eq compstate[nmatches] ]]; then
-  compadd -U -S '' "$group[@]" "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" \
-          -p "$linepath" - "${(@)exppaths}"
+      $#exppaths -eq 0 && nm -eq compstate[nmatches] ]]; then
+  compadd -QU -S '' "$group[@]" "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" \
+          -M 'r:|/=* r:|=*' -p "$linepath" - "${(@)exppaths}"
 fi
 
 [[ nm -eq compstate[nmatches] ]]
diff --git a/Completion/Core/compdump b/Completion/Core/compdump
index b7682bd50..f2729acc5 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,12 +9,14 @@
 # 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.
 
+emulate -L zsh
+
+typeset _d_file _d_f _d_bks _d_line _d_als
+
 _d_file=${compconfig[dumpfile]-${0:h}/compinit.dump}
 
 typeset -U _d_files
@@ -22,8 +24,6 @@ _d_files=( ${^~fpath}/_(|*[^~])(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.
 
@@ -88,4 +88,5 @@ done >> $_d_file
 
 print >> $_d_file
 
-unset _d_line _d_zle _d_bks _d_als _d_f _f_file
+unfunction compdump
+autoload -U compdump
diff --git a/Completion/Core/compinit b/Completion/Core/compinit
index f4aa80f21..9302d8243 100644
--- a/Completion/Core/compinit
+++ b/Completion/Core/compinit
@@ -41,15 +41,14 @@
 # See the file `compdump' for how to speed up initialisation.
 
 # If we got the `-d'-flag, we will automatically dump the new state (at
-# the end).
-# `-f dir' is used to pass down the directory where this file was
-#   found.  This is necessary if functionargzero is not set.
-# If we were given an argument, this will be taken as the name of the
-# file in which to store the dump.
-
-_i_fdir=''
-_i_dumpfile=''
-_i_autodump=0
+# the end).  This takes the dumpfile as an argument.  -d (with the
+# default dumpfile) is now the default; to turn off dumping use -D.
+
+emulate -L zsh
+
+typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=1
+typeset _i_tag _i_file _i_addfiles
+
 while [[ $# -gt 0 && $1 = -[df] ]]; do
   if [[ "$1" = -d ]]; then
     _i_autodump=1
@@ -58,57 +57,30 @@ while [[ $# -gt 0 && $1 = -[df] ]]; do
       _i_dumpfile="$1"
       shift
     fi
+  elif [[ "$1" = -D ]]; then
+    _i_autodump=0
   elif [[ "$1" = -f ]]; then
-    # Used by compinstall to pass down directory where compinit was found
+    # Not used any more; use _compdir
     shift
-    _i_fdir="$1"
     shift
   fi
 done
-# Get the directory if we don't have it already and we can
-if [[ -z "$_i_fdir" && -o functionargzero && $0 = */* ]]; then
-  _i_fdir=${0:h}
-fi
 
 # The associative array containing the definitions for the commands.
 # Definitions for patterns will be stored in the normal array `_patcomps'.
 
-typeset -A _comps
+typeset -gA _comps
 _patcomps=()
 
 # This is the associative array used for configuration.
 
-typeset -A compconfig
+typeset -gA compconfig
 
 # Standard initialisation for `compconfig'.
 if [[ -n $_i_dumpfile ]]; then
   # Explicitly supplied dumpfile.
   compconfig[dumpfile]="$_i_dumpfile"
-elif [[ -o functionargzero ]]; then
-  # We can deduce it from the name of this script
-  compconfig[dumpfile]="$0.dump"
-elif [[ -n $_i_fdir ]]; then
-  # We were told what directory to use.
-  compconfig[dumpfile]="$_i_fdir/compinit.dump"
 else
-  compconfig[dumpfile]=''
-fi
-
-if [[ -n $compconfig[dumpfile] ]]; then
-  # Check the file is writeable.  If it doesn't exist, the
-  # only safe way is to try and create it.
-  if [[ -f $compconfig[dumpfile] ]]; then
-    [[ -w $compconfig[dumpfile] ]] || compconfig[dumpfile]=''
-  elif touch $compconfig[dumpfile] >& /dev/null; then
-    rm -f $compconfig[dumpfile]
-  else
-    compconfig[dumpfile]=''
-  fi
-fi
-
-if [[ -z $compconfig[dumpfile] ]]; then
-  # If no dumpfile given, or it was not writeable, then use
-  # user's ZDOTDIR.
   compconfig[dumpfile]="${ZDOTDIR:-$HOME}/.zcompdump"
 fi
 
@@ -322,19 +294,24 @@ compconf() {
 
 typeset -U _i_files
 _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) )
-if [[ $#_i_files -lt 20 ]]; then
-  # Too few files:  we need some more directories
-  # Assume that we need to add the compinit directory to fpath.
-  if [[ -n $_i_fdir ]]; then
-    if [[ $_i_fdir = */Core ]]; then
+if [[ $#_i_files -lt 20 || $_compdir = */Core || -d $_compdir/Core ]]; then
+  # Too few files:  we need some more directories,
+  # or we need to check that all directories (not just Core) are present.
+  if [[ -n $_compdir ]]; then
+    _i_addfiles=()
+    if [[ $_compdir = */Core ]]; then
       # Add all the Completion subdirectories
-      fpath=(${_i_fdir:h}/*(/) $fpath)
-    elif [[ -d $_i_fdir/Core ]]; then
+      _i_addfiles=(${_compdir:h}/*(/))
+    elif [[ -d $_compdir/Core ]]; then
       # Likewise
-      fpath=(${_i_fdir}/*(/) $fpath)
-    else
-      fpath=($_i_fdir $fpath)
+      _i_addfiles=(${_compdir}/*(/))
     fi
+    for _i_line in {1..$#i_addfiles}; do
+      _i_file=${_i_addfiles[$_i_line]}
+      [[ -d $_i_file && -z ${fpath[(r)$_i_$file]} ]] ||
+        _i_addfiles[$_i_line]=
+    done
+    fpath=($_i_addfiles $fpath)
     _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) )
   fi
 fi
@@ -346,9 +323,13 @@ for _i_line in complete-word delete-char-or-list expand-or-complete \
   menu-expand-or-complete reverse-menu-complete; do
   zle -C $_i_line .$_i_line _main_complete
 done
+zle -la menu-select && zle -C menu-select .menu-select _main_complete
 
 _i_done=''
 
+# Make sure compdump is available, even if we aren't going to use it.
+autoload -U compdump compinstall
+
 # If we have a dump file, load it.
 
 if [[ -f "$compconfig[dumpfile]" ]]; then
@@ -357,7 +338,6 @@ if [[ -f "$compconfig[dumpfile]" ]]; then
     builtin . "$compconfig[dumpfile]"
     _i_done=yes
   fi
-  unset _i_line
 fi
 if [[ -z "$_i_done" ]]; then
   for _i_dir in $fpath; do
@@ -381,13 +361,12 @@ if [[ -z "$_i_done" ]]; then
     done
   done
 
-  unset _i_dir _i_line _i_file _i_tag
-
   # If autodumping was requested, do it now.
 
-  if [[ -n ${_i_fdir} && $_i_autodump = 1 ]]; then
-    builtin . ${_i_fdir}/compdump
+  if [[ $_i_autodump = 1 ]]; then
+    compdump
   fi
 fi
 
-unset _i_files _i_initname _i_done _i_autodump _i_fdir _i_dumpfile
+unfunction compinit
+autoload -U compinit
diff --git a/Completion/Core/compinstall b/Completion/Core/compinstall
index 5086cc7d2..52b4bf707 100644
--- a/Completion/Core/compinstall
+++ b/Completion/Core/compinstall
@@ -1,11 +1,12 @@
 # This script is to be run by a user to set up the new function based
 # completion system.  The functions themselves are assumed to be already
 # available in some directory; they should have been installed with the
-# the shell (except we haven't written that yet).
+# the shell.  If they have been, the commands `autoload -U compinit; compinit'
+# in the shell startup file should be enough, although you can run
+# compinstall for more configuration choices.
 #
-# Source this script (e.g. `. /path/compinstall') and answer the questions.
-#
-# Normally, this will alter ~/.zshrc (or wherever ZDOTDIR puts it), but you
+# Simply run this script as a function and answer the questions.
+# Normally it will alter ~/.zshrc (or wherever ZDOTDIR puts it), but you
 # can make that unwritable and it will leave the lines in a temporary file
 # instead.  It doesn't matter if .zshrc didn't exist before.  If your
 # .zshrc usually exits before the end, then you should take the code added
@@ -23,33 +24,13 @@
 #  - Could add code for setting other completers and options.
 #  - Could add keys for context-sensitive help.
 
-# Save the options.  We will need to trap ^C to make sure they get
-# restored properly.
-typeset -A _ci_options
-_ci_options=($(setopt kshoptionprint;setopt))
-[[ -o kshoptionprint ]] || _ci_options[kshoptionprint]=off
-[[ -o monitor ]] && _ci_options[monitor]=on
-[[ -o zle ]] && _ci_options[zle]=on
-
-emulate zsh
-
-TRAPINT() { 
-  unsetopt ${(k)_ci_options[(R)off]}
-  setopt ${(k)_ci_options[(R)on]}
-
-  unset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines
-  unset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline
-  unset _ci_endline _ci_ifile _ci_tmpf _ci_defaults _ci_compconf _ci_warn
-  unset _ci_dtype _ci_existing _ci_line
-
-  if (( $1 )); then
-    print Aborted.
-    unfunction TRAPINT
-    return 1
-  fi
-  return 0
-}
 
+emulate -L zsh
+
+typeset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines
+typeset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline
+typeset _ci_endline _ci_ifile _ci_tmpf _ci_compconf _ci_warn
+typeset _ci_dtype _ci_existing _ci_line _ci_end
 
 # Look for the defaults.
 _ci_startline='# The following lines were added by compinstall'
@@ -60,6 +41,7 @@ _ci_lines=''
 _ci_existing=''
 
 typeset -A _ci_defaults
+
 if [[ -f $_ci_ifile ]]; then
   # This assumes the lines haven't been altered by the user too much
   # after they were added.
@@ -68,13 +50,14 @@ if [[ -f $_ci_ifile ]]; then
   while read -rA _ci_line; do
     if (( $_ci_compconf )); then
       # parse a compconf component as first argument
-      if [[ $_ci_line[-1] == \\ ]]; then
-	_ci_line=(${_ci_line[1,-2]})
-      else
+      if [[ $_ci_line[-1] != \\ ]]; then
+	_ci_end=-1
 	_ci_compconf=0
+      else
+	_ci_end=-2
       fi
       if [[ $_ci_line[1] = *=* ]]; then
-	_ci_f="${${_ci_line[*]}#*=}"
+	_ci_f="${${_ci_line[1,$_ci_end]}#*=}"
 	if [[ $_ci_f = \'*\' ]]; then
 	  # strip quotes
 	  _ci_f=${_ci_f[2,-2]//\'\\\'\'/\'}
@@ -83,10 +66,12 @@ if [[ -f $_ci_ifile ]]; then
       fi
       _ci_existing="${_ci_existing}  $_ci_line
 "
-    elif [[ $_ci_line[1] = . && $_ci_line[2] = */compinit ]]; then
-      # parse the line sourcing compinit
-      [[ $_ci_line[3] = -f ]]  && _ci_fdir=$_ci_line[4]
+    elif [[ $_ci_line[1] = compinit ]]; then
+      # parse the line running compinit
+      [[ $_ci_line[2] = -f ]]  && _ci_fdir=$_ci_line[3]
       [[ $_ci_line[-2] = -d ]] && _ci_dumpfile=$_ci_line[-1]
+    elif [[ $_ci_line[1] = _compdir=* ]]; then
+      _ci_fdir=${_ci_line[1]##_compdir=}
     elif [[ $_ci_line[1] = compconf ]]; then
       # parse a compconf component as second argument (should be completer)
       [[ $_ci_line[2] = completer=* ]] &&
@@ -94,7 +79,7 @@ if [[ -f $_ci_ifile ]]; then
       [[ $_ci_line[-1] == \\ ]] && _ci_compconf=1
       _ci_existing="${_ci_existing}$_ci_line
 "
-    elif [[ $_ci_line[1] != \#* ]]; then
+    elif [[ $_ci_line[1] != \#* && $_ci_line[1] != (autoload|\[\[) ]]; then
       if [[ -z $_ci_warn ]]; then
 	_ci_warn=1
 	print "Warning:  existing lines in compinstall setup not understood:"
@@ -109,38 +94,42 @@ fi
 
 # Find out where the completion functions are kept.
 
-if [[ -z $_ci_fdir || ! -f $_ci_f/compinit || ! -f $_ci_f/compdump ]]; then
+if [[ -z $_ci_fdir || ! -f ${~_ci_fdir}/compinit ||
+  ! -f ${~_ci_fdir}/compdump ]]; then
   for _ci_f in $fpath; do
     if [[ $_ci_f != . && -f $_ci_f/compinit && -f $_ci_f/compdump ]]; then
       _ci_fdir=$_ci_f
       break
+    elif [[ $_ci_f != . && -f $_ci_f/Core/compinit &&
+      -f $_ci_f/Core/compdump ]]
+    then
+      _ci_fdir=$_ci_f/Core
+      break
     fi
   done
 fi
 
 if [[ -z $_ci_fdir || ! -d ${~_ci_fdir} ]]; then
-  print "Trying to find where the completion functions are..."
-  if [[ $0 = */* && -o functionargzero &&
-        -f $0:h/compinit && -f $0:h/compdump ]]; then
-    _ci_fdir=$0:h
-    print "Using my directory, $_ci_fdir"
-  else
-    # more guesses?
-    print \
+  print \
 "Please edit the name of the directory where the completion functions are
 installed.  If they are not installed, you will need to find them in the
 Completion/* directories of the zsh distribution and install them yourself,
 or insult your system manager for incompetence."
-    vared -c _ci_fdir
-    while [[ ! -d ${~_ci_fdir} || ! -f ${~_ci_fdir}/compinit || 
-      ! -f ${~_ci_fdir}/compdump ]]; do
-      print "I can't find them in that directory.  Try again or abort."
-      vared _ci_fdir
-    done
+  vared -c _ci_fdir
+  while [[ ! -d ${~_ci_fdir} || 
+    ((! -f ${~_ci_fdir}/compinit || ! -f ${~_ci_fdir}/compdump) &&
+    (! -f ${~_ci_fdir}/Core/compinit || ! -f ${~_ci_fdir}/Core/compdump)) ]]
+  do
+    print "I can't find them in that directory.  Try again or abort."
+    vared _ci_fdir
+  done
+  if [[ -f ${~_ci_fdir}/Core/compinit && ! -f ${~_ci_fdir}/compinit ]]; then
+    _ci_fdir=$_ci_fdir/Core
   fi
 else
   print "Keeping existing completion directiory $_ci_fdir"
 fi
+
 if [[ ${~_ci_fdir} != /* ]]; then
   _ci_fdir=$(cd $_ci_fdir;builtin pwd)
 fi
@@ -148,6 +137,7 @@ fi
 # Check if this is in fpath already, else put it there (with ~'s expanded).
 _ci_f=${~_ci_fdir}
 [[ -z ${fpath[(r)$_ci_f]} ]] && fpath=($_ci_f $fpath)
+
 # Contract $HOME to ~ in the parameter to be used for writing.
 _ci_fdir=${_ci_fdir/#$HOME/\~}
 
@@ -166,7 +156,7 @@ fi
 # Set up the dumpfile
 _ci_dtype=existing
 if [[ -z $_ci_dumpfile ]]; then
-  _ci_dumpfile="${_ci_fdir}/compinit.dump"
+  _ci_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
   _ci_dtype=standard
 fi
 
@@ -184,7 +174,6 @@ else
 I will force completion to dump its status, which will speed up the shell's
 start-up considerably.  However, I can't write the file I'd like to, namely
 ${_ci_dumpfile}.  Please edit a replacement."
-  _ci_dumpfile='~/.compinit.dump'
   vared _ci_dumpfile
   while ! touch ${~_ci_dumpfile} >& /dev/null; do
     print "Sorry, I can't write that either.  Try again."
@@ -193,7 +182,10 @@ ${_ci_dumpfile}.  Please edit a replacement."
   [[ -s $_ci_dumpfile ]] || rm -f $_ci_dumpfile
 fi
 
-_ci_lines="${_ci_lines}. $_ci_fdir/compinit -f $_ci_fdir -d"
+_ci_lines="${_ci_lines}_compdir=$_ci_fdir
+[[ -z \$fpath[(r)\$_compdir] ]] && fpath=(\$_compdir \$fpath)
+autoload -U compinit
+compinit"
 [[ $_ci_dtype != standard ]] && _ci_lines="${_ci_lines} $_ci_dumpfile"
 _ci_lines="${_ci_lines}
 "
@@ -363,6 +355,7 @@ $_ci_lines$_ci_endline" >>$_ci_ifile &&
   print "\nSuccessfully appended lines to $_ci_ifile."
 fi
 
-TRAPINT 0
+unfunction compinstall
+autoload -U compinstall
 
 return 0
diff --git a/Completion/User/_hosts b/Completion/User/_hosts
index 911cea03b..a0aca0a62 100644
--- a/Completion/User/_hosts
+++ b/Completion/User/_hosts
@@ -1,3 +1,5 @@
-#compdef ftp ncftp ping rwho rup xping traceroute nslookup
+#compdef ftp ncftp ping rwho rup xping traceroute nslookup telnet
 
-compgen -k hosts
+: ${(A)hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
+
+compgen -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -k hosts