about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/_arguments2
-rw-r--r--Completion/Base/_brace_parameter2
-rw-r--r--Completion/Base/_command_names24
-rw-r--r--Completion/Base/_describe2
-rw-r--r--Completion/Base/_equal4
-rw-r--r--Completion/Base/_first2
-rw-r--r--Completion/Base/_job26
-rw-r--r--Completion/Base/_regex_arguments3
-rw-r--r--Completion/Base/_tilde17
-rw-r--r--Completion/Base/_values2
-rw-r--r--Completion/Builtins/_aliases6
-rw-r--r--Completion/Builtins/_arrays2
-rw-r--r--Completion/Builtins/_bg_jobs5
-rw-r--r--Completion/Builtins/_bindkey6
-rw-r--r--Completion/Builtins/_builtin2
-rw-r--r--Completion/Builtins/_cd3
-rw-r--r--Completion/Builtins/_command4
-rw-r--r--Completion/Builtins/_compdef12
-rw-r--r--Completion/Builtins/_disable8
-rw-r--r--Completion/Builtins/_enable8
-rw-r--r--Completion/Builtins/_fc5
-rw-r--r--Completion/Builtins/_functions2
-rw-r--r--Completion/Builtins/_hash4
-rw-r--r--Completion/Builtins/_jobs5
-rw-r--r--Completion/Builtins/_kill6
-rw-r--r--Completion/Builtins/_popd39
-rw-r--r--Completion/Builtins/_set8
-rw-r--r--Completion/Builtins/_stat3
-rw-r--r--Completion/Builtins/_trap6
-rw-r--r--Completion/Builtins/_unhash9
-rw-r--r--Completion/Builtins/_wait17
-rw-r--r--Completion/Builtins/_which14
-rw-r--r--Completion/Builtins/_zle4
-rw-r--r--Completion/Builtins/_zmodload4
-rw-r--r--Completion/Commands/_bash_completions2
-rw-r--r--Completion/Commands/_history_complete_word123
-rw-r--r--Completion/Commands/_read_comp8
-rw-r--r--Completion/Core/_approximate25
-rw-r--r--Completion/Core/_main_complete11
-rw-r--r--Completion/Core/_normal6
-rw-r--r--Completion/Core/_options3
-rw-r--r--Completion/Core/_parameters8
-rw-r--r--Completion/Core/_path_files32
-rw-r--r--Completion/Core/compinit4
-rw-r--r--Completion/Debian/_apt2
-rw-r--r--Completion/User/_cvs10
-rw-r--r--Completion/User/_gdb3
-rw-r--r--Completion/User/_man2
-rw-r--r--Completion/User/_mh7
-rw-r--r--Completion/User/_nslookup2
-rw-r--r--Completion/User/_tar3
-rw-r--r--Completion/User/_urls2
-rw-r--r--Completion/User/_users2
-rw-r--r--Completion/User/_whereis5
-rw-r--r--Completion/User/_whois1
-rw-r--r--Completion/X/_x_font2
-rw-r--r--Completion/X/_x_window2
-rw-r--r--Completion/X/_xmodmap2
58 files changed, 287 insertions, 246 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments
index 18ddf0327..ca8f42c61 100644
--- a/Completion/Base/_arguments
+++ b/Completion/Base/_arguments
@@ -3,8 +3,6 @@
 # Complete the arguments of the current command according to the
 # descriptions given as arguments to this function.
 
-setopt localoptions extendedglob
-
 local long cmd="$words[1]" descr mesg
 
 long=$argv[(I)--]
diff --git a/Completion/Base/_brace_parameter b/Completion/Base/_brace_parameter
index 2bf7b6a6d..9ed4867ef 100644
--- a/Completion/Base/_brace_parameter
+++ b/Completion/Base/_brace_parameter
@@ -6,8 +6,6 @@ _parameters -e
 # Without the `-e' option, we would use the following (see the file
 # Core/_parameters for more enlightenment).
 
-# setopt localoptions extendedglob
-
 # local lp ls n q
 
 # if [[ "$SUFFIX" = *\}* ]]; then
diff --git a/Completion/Base/_command_names b/Completion/Base/_command_names
index 2218aac21..79bd46e84 100644
--- a/Completion/Base/_command_names
+++ b/Completion/Base/_command_names
@@ -4,24 +4,34 @@
 # complete only external commands and executable files. This and a
 # `-' as the first argument is then removed from the arguments.
 
-local nm=$compstate[nmatches] ret=1 expl type=-c
+local nm=$compstate[nmatches] ret=1 expl ext
 
 if [[ "$1" = -e ]]; then
-  type=-m
+  ext=yes
   shift
 elif [[ "$1" = - ]]; then
   shift
 fi
 
 # Complete jobs in implicit fg and bg
-if [[ $type = -c && "$PREFIX[1]" = "%" ]]; then
-  _description expl job
-  compgen "$expl[@]" "$@" -j -P '%'
+if [[ -z "$ext" && "$PREFIX[1]" = "%" ]]; then
+  _job -P '%'
   [[ nm -ne compstate[nmatches] ]] && return
 fi
 
-_description expl command
-compgen "$expl[@]" "$@" $type && ret=0
+_description expl 'external command'
+compadd "$expl[@]" "$@" - "${(k@)commands}" && ret=0
+
+if [[ -z "$ext" ]]; then
+  _description expl 'builtin command'
+  compadd "$expl[@]" "$@" - "${(k@)builtins[(R)^?disabled*]}" && ret=0
+  _description expl 'shell function'
+  compadd "$expl[@]" "$@" - "${(k@)functions[(R)^?disabled*]}" && ret=0
+  _description expl 'alias'
+  compadd "$expl[@]" "$@" - "${(k@)raliases[(R)^?disabled*]}" && ret=0
+  _description expl 'reserved word'
+  compadd "$expl[@]" "$@" - "${(k@)reswords[(R)^?disabled*]}" && ret=0
+fi
 
 if [[ nm -eq compstate[nmatches] ]]; then
   _description expl 'executable file or directory'
diff --git a/Completion/Base/_describe b/Completion/Base/_describe
index 2bb32ad35..e59dc1593 100644
--- a/Completion/Base/_describe
+++ b/Completion/Base/_describe
@@ -2,8 +2,6 @@
 
 # This can be used to add options or values with descriptions as matches.
 
-setopt localoptions extendedglob
-
 local isopt cmd opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide
 
 cmd="$words[1]"
diff --git a/Completion/Base/_equal b/Completion/Base/_equal
index 14f28703c..1ba92cdc6 100644
--- a/Completion/Base/_equal
+++ b/Completion/Base/_equal
@@ -3,6 +3,6 @@
 local expl
 
 _description expl alias
-compgen "$expl[@]" -a
+compadd "$@" "$expl[@]" - "${(@k)aliases[(R)^?disabled*]}"
 _description expl command
-compgen "$expl[@]" -m
+compadd "$@" "$expl[@]" - "${(k@)commands}"
diff --git a/Completion/Base/_first b/Completion/Base/_first
index ba5ef6c24..d259824cc 100644
--- a/Completion/Base/_first
+++ b/Completion/Base/_first
@@ -55,7 +55,7 @@
 #         else
 #           _description -V expl "history ($n)"
 #         fi
-#         if compgen "$expl[@]" -Q -H $(( i*10 )) ''; then
+#         if compadd "$expl[@]" -Q - "${(@)historywords:#[\$'\"]*}"; 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 _compskip.
diff --git a/Completion/Base/_job b/Completion/Base/_job
new file mode 100644
index 000000000..081956c51
--- /dev/null
+++ b/Completion/Base/_job
@@ -0,0 +1,26 @@
+#autoload
+
+local expl disp jobs job jids
+
+if [[ "$1" = -r ]]; then
+  jids=( "${(@k)jobstates[(R)running*]}" )
+  shift
+  _description expl 'running job'
+elif [[ "$1" = -s ]]; then
+  jids=( "${(@k)jobstates[(R)running*]}" )
+  shift
+  _description expl 'suspended job'
+else
+  [[ "$1" = - ]] && shift
+  jids=( "${(@k)jobtexts}" )
+  _description expl job
+fi
+
+disp=()
+jobs=()
+for job in "$jids[@]"; do
+  disp=( "$disp[@]" "[${(l:2:: :)job}] ${jobtexts[$job]}" )
+  jobs=( "$jobs[@]" "$job" )
+done
+
+compadd "$@" "$expl[@]" -ld disp - "$jobs[@]"
diff --git a/Completion/Base/_regex_arguments b/Completion/Base/_regex_arguments
index 2608fda11..e2858e66c 100644
--- a/Completion/Base/_regex_arguments
+++ b/Completion/Base/_regex_arguments
@@ -206,7 +206,6 @@ _ra_gen_func () {
 
   print -lr - \
     "$funcname () {" \
-      'setopt localoptions extendedglob' \
       'local _ra_state _ra_left _ra_right _ra_actions' \
       "_ra_state=$start" \
       '_ra_left=' \
@@ -323,8 +322,6 @@ _ra_gen_parse_state () {
 }
 
 _regex_arguments () {
-  setopt localoptions extendedglob
-
   local funcname="_regex_arguments_tmp"
   local funcdef
 
diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde
index d871ddc11..0b81f75a1 100644
--- a/Completion/Base/_tilde
+++ b/Completion/Base/_tilde
@@ -2,12 +2,7 @@
 
 # We use all named directories and user names here. If this is too slow
 # for you or if there are too many of them, you may want to use
-# `compgen -k friends -qS/' or something like that. To get all user names
-# if there are no matches in the `friends' array, add
-#   `(( compstate[nmatches] )) || compgen -nu -qS/'
-# below that.
-
-setopt localoptions extendedglob
+# `compadd -qS/ - "$friends[@]"' or something like that.
 
 local d s dirs list lines revlines i
 
@@ -20,21 +15,20 @@ else
 fi
 
 if [[ -prefix [-+] ]]; then
-  lines=(${(f)"$(dirs -v)"})
+  lines=("$PWD" "$dirstack[@]")
   integer i
   if [[ ( -prefix - && ! -o pushdminus ) ||
 	( -prefix + && -o pushdminus ) ]]; then
     revlines=( $lines )
     for (( i = 1; i <= $#lines; i++ )); do
-      lines[$i]="$((i-1)) -- ${revlines[-$i]##[0-9]#[	 ]#}"
+      lines[$i]="$((i-1)) -- ${revlines[-$i]}"
     done
   else
     for (( i = 1; i <= $#lines; i++ )); do
-      lines[$i]="$((i-1)) -- ${lines[$i]##[0-9]#[	 ]#}"
+      lines[$i]="$((i-1)) -- ${lines[$i]}"
     done
   fi
   list=(${lines%% *})
-
   compset -P '[-+]'
   _description d 'directory stack'
   compadd "$d[@]" -V dirs -S/ -ld lines -Q - "$list[@]" 
@@ -45,6 +39,5 @@ else
   else
     _description d 'named directory'
   fi
-  compgen "$d[@]" -n "$s[@]"
+  compadd "$d[@]" "$s[@]" - "${(@k)nameddirs}"
 fi
-
diff --git a/Completion/Base/_values b/Completion/Base/_values
index fb70f6e7f..e4ef8af68 100644
--- a/Completion/Base/_values
+++ b/Completion/Base/_values
@@ -1,7 +1,5 @@
 #autoload
 
-setopt localoptions extendedglob
-
 if compvalues -i "$@"; then
 
   local noargs args opts descr action expl sep
diff --git a/Completion/Builtins/_aliases b/Completion/Builtins/_aliases
index 3e4b789b6..0189d6cf3 100644
--- a/Completion/Builtins/_aliases
+++ b/Completion/Builtins/_aliases
@@ -2,5 +2,7 @@
 
 local expl
 
-_description expl alias
-compgen "$expl[@]" -a
+_description expl 'regular alias'
+compadd "$expl[@]" - "${(@k)raliases[(R)^?disabled*]}"
+_description expl 'global alias'
+compadd "$expl[@]" - "${(@k)galiases[(R)^?disabled*]}"
diff --git a/Completion/Builtins/_arrays b/Completion/Builtins/_arrays
index 20681f527..a2aa813b6 100644
--- a/Completion/Builtins/_arrays
+++ b/Completion/Builtins/_arrays
@@ -3,4 +3,4 @@
 local expl
 
 _description expl array
-compgen "$expl[@]" -A
+compadd "$expl[@]" - "${(@k)parameters[(R)*array*]}"
diff --git a/Completion/Builtins/_bg_jobs b/Completion/Builtins/_bg_jobs
index 65f21b483..6d6a8fcc4 100644
--- a/Completion/Builtins/_bg_jobs
+++ b/Completion/Builtins/_bg_jobs
@@ -1,6 +1,3 @@
 #compdef bg
 
-local expl
-
-_description expl 'suspended job'
-compgen "$expl[@]" -z -P '%'
+_job -s -P '%'
diff --git a/Completion/Builtins/_bindkey b/Completion/Builtins/_bindkey
index 891e2cedb..3f964e704 100644
--- a/Completion/Builtins/_bindkey
+++ b/Completion/Builtins/_bindkey
@@ -3,7 +3,7 @@
 # Normally, this completes names of zle widgets, whether the builtin ones
 # or ones defined by the user.  Note that a - allows a wildcard before it,
 # so h-b-s-b will complete to history-beginning-search-backward.  You
-# can alter this by removing the -M ... from the second compgen.
+# can alter this by removing the -M ... from the second compadd.
 #
 # Where appropriate, will complete keymaps instead of widgets.
 
@@ -11,8 +11,8 @@ local expl
 
 if [[ "$words[2]" = -*[DAN]* || "$words[CURRENT-1]" = -*M ]]; then
   _description expl keymap
-  compadd "$expl[@]" - $(bindkey -l)
+  compadd "$expl[@]" - "$zlekeymaps[@]"
 else
   _description expl widget
-  compgen "$expl[@]" -b -M 'r:|-=* r:|=*'
+  compadd "$expl[@]" -M 'r:|-=* r:|=*' - "${(@k)zlewidgets}"
 fi
diff --git a/Completion/Builtins/_builtin b/Completion/Builtins/_builtin
index f925b88a8..06ef1c246 100644
--- a/Completion/Builtins/_builtin
+++ b/Completion/Builtins/_builtin
@@ -8,5 +8,5 @@ else
   local expl
 
   _description expl 'builtin command'
-  compgen "$expl[@]" -eB
+  compadd "$expl[@]" "$@" - "${(k@)builtins[(R)^?disabled*]}"
 fi
diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd
index 838b1af24..b407b5a85 100644
--- a/Completion/Builtins/_cd
+++ b/Completion/Builtins/_cd
@@ -11,8 +11,7 @@
 #    it's not a lot of use.  If you don't type the + or - it will
 #    complete directories as normal.
 
-emulate -L zsh
-setopt extendedglob nonomatch
+setopt localoptions nonomatch
 
 local expl
 
diff --git a/Completion/Builtins/_command b/Completion/Builtins/_command
index 4ae274f1f..9f54aae80 100644
--- a/Completion/Builtins/_command
+++ b/Completion/Builtins/_command
@@ -6,6 +6,6 @@ if [[ CURRENT -ge 3 ]]; then
 else
   local expl
 
-  _description expl command
-  compgen "$expl[@]" -em
+  _description expl 'external command'
+  compadd "$expl[@]" "$@" - "${(k@)commands}"
 fi
diff --git a/Completion/Builtins/_compdef b/Completion/Builtins/_compdef
index 1df5758b3..4208c2689 100644
--- a/Completion/Builtins/_compdef
+++ b/Completion/Builtins/_compdef
@@ -1,6 +1,6 @@
 #compdef compdef
 
-local func base=2
+local expl func base=2
 
 while [[ $words[base] = -* ]]; do
   case $words[base] in
@@ -12,11 +12,13 @@ while [[ $words[base] = -* ]]; do
 done
 
 if [ "$delete" ]; then
-  compadd ${(k)_comps}
+  _description expl 'completed command'
+  compadd "$expl[@]" - ${(k)_comps}
 else
-  if [[ CURRENT -eq base  ]]; then
-    for func in ${^~fpath:/.}/_(|*[^~])(N:t); compadd -P_ - ${func#_}
+  if [[ CURRENT -eq base ]]; then
+    _description expl 'completion function'
+    compadd "$expl[@]" - ${^fpath:/.}/_(|*[^~])(N:t)
   else
-    compgen -c
+    _command_names
   fi
 fi
diff --git a/Completion/Builtins/_disable b/Completion/Builtins/_disable
index b219f4b7e..fe6b991b2 100644
--- a/Completion/Builtins/_disable
+++ b/Completion/Builtins/_disable
@@ -4,19 +4,19 @@ local prev="$words[CURRENT-1]" ret=1 expl
 
 if [[ "$prev" = -*a* ]]; then
   _description expl alias
-  compgen "$expl[@]" -ea && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)aliases[(R)^?disabled*]}" && ret=0
 fi
 if [[ "$prev" = -*f* ]]; then
   _description expl 'shell function'
-  compgen "$expl[@]" -eF && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)functions[(R)^?disabled*]}" && ret=0
 fi
 if [[ "$prev" = -*r* ]]; then
   _description expl 'reserved word'
-  compgen "$expl[@]" -ew && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)reswords[(R)^?disabled*]}" && ret=0
 fi
 if [[ "$prev" != -* ]]; then
   _description expl 'builtin command'
-  compgen "$expl[@]" -eB && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)builtins[(R)^?disabled*]}" && ret=0
 fi
 
 return ret
diff --git a/Completion/Builtins/_enable b/Completion/Builtins/_enable
index a698a3895..b4f0356bc 100644
--- a/Completion/Builtins/_enable
+++ b/Completion/Builtins/_enable
@@ -4,19 +4,19 @@ local prev="$words[CURRENT-1]" ret=1 expl
 
 if [[ "$prev" = -*a* ]]; then
   _description expl alias
-  compgen "$expl[@]" -da && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)aliases[(R)?disabled*]}" && ret=0
 fi
 if [[ "$prev" = -*f* ]]; then
   _description expl 'shell function'
-  compgen "$expl[@]" -dF && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)functions[(R)?disabled*]}" && ret=0
 fi
 if [[ "$prev" = -*r* ]]; then
   _description expl 'reserved word'
-  compgen "$expl[@]" -dw && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)reswords[(R)?disabled*]}" && ret=0
 fi
 if [[ "$prev" != -* ]]; then
   _description expl 'builtin command'
-  compgen "$expl[@]" -dB && ret=0
+  compadd "$expl[@]" "$@" - "${(k@)builtins[(R)?disabled*]}" && ret=0
 fi
 
 return ret
diff --git a/Completion/Builtins/_fc b/Completion/Builtins/_fc
index 8d5c82763..c2eaab7bb 100644
--- a/Completion/Builtins/_fc
+++ b/Completion/Builtins/_fc
@@ -1,10 +1,9 @@
 #compdef fc
 
-local prev="$words[CURRENT-1]" expl
+local prev="$words[CURRENT-1]"
 
 if [[ "$prev" = -*e ]]; then
-  _description expl command
-  compgen "$expl[@]" -c
+  _command_names -e
 elif [[ "$prev" = -[ARWI]## ]]; then
   _files
 fi
diff --git a/Completion/Builtins/_functions b/Completion/Builtins/_functions
index 7aa30b7bc..d5f32d2e3 100644
--- a/Completion/Builtins/_functions
+++ b/Completion/Builtins/_functions
@@ -3,4 +3,4 @@
 local expl
 
 _description expl 'shell function'
-compgen "$expl[@]" -F
+compadd "$expl[@]" "$@" - "${(k@)functions[(R)^?disabled*]}"
diff --git a/Completion/Builtins/_hash b/Completion/Builtins/_hash
index c8169c590..c06d63699 100644
--- a/Completion/Builtins/_hash
+++ b/Completion/Builtins/_hash
@@ -7,11 +7,11 @@ if [[ "$words[2]" = -*d* ]]; then
     _path_files -g '*(-/)'
   else
     _description expl 'named directory'
-    compgen "$expl[@]" -n -q -S '='
+    compadd "$expl[@]" -q -S '=' - "${(@k)nameddirs}"
   fi
 elif compset -P 1 '*\='; then
   _files -/g '*(*)'
 else
   _description expl command
-  compgen "$expl[@]" -m -q -S '='
+  compadd "$expl[@]" -q -S '=' - "${(@k)commands}"
 fi
diff --git a/Completion/Builtins/_jobs b/Completion/Builtins/_jobs
index b1ff31b4a..c17b73c92 100644
--- a/Completion/Builtins/_jobs
+++ b/Completion/Builtins/_jobs
@@ -1,6 +1,3 @@
 #compdef disown fg jobs
 
-local expl
-
-_description expl job
-compgen "$expl[@]" -j -P '%'
+_job -P '%'
diff --git a/Completion/Builtins/_kill b/Completion/Builtins/_kill
index da70cf753..b79bfd6c0 100644
--- a/Completion/Builtins/_kill
+++ b/Completion/Builtins/_kill
@@ -8,9 +8,9 @@ if compset -P 1 -; then
 else
   local ret=1
 
-  _description expl job
-  compgen "$expl[@]" -P '%' -j && ret=0
-  list=("${(@Mr:COLUMNS-1:)${(f@)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
+  _job && ret=0
+
+  list=("${(@M)${(f@)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
   _description expl 'process ID'
   compadd "$expl[@]" -ld list - ${${${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *} &&
     ret=0
diff --git a/Completion/Builtins/_popd b/Completion/Builtins/_popd
index 9054befb7..07dc4a87f 100644
--- a/Completion/Builtins/_popd
+++ b/Completion/Builtins/_popd
@@ -5,6 +5,45 @@
 # way round if pushdminus is set). Note that this function is also called
 # from _cd for cd and pushd.
 
+setopt localoptions nonomatch
+
+[[ $PREFIX = [-+]* ]] || return 1
+
+local expl list lines revlines ret=1 i
+
+IPREFIX=$PREFIX[1]
+PREFIX=$PREFIX[2,-1]
+
+# get the list of directories with their canonical number
+# and turn the lines into an array, removing the current directory
+lines=( "$dirstack[@]" )
+if [[ ( $IPREFIX = - && ! -o pushdminus ) ||
+      ( $IPREFIX = + && -o pushdminus ) ]]; then
+  integer i
+  revlines=( $lines )
+  for (( i = 1; i <= $#lines; i++ )); do
+    lines[$i]="$((i-1)) -- ${revlines[-$i]}"
+  done
+else
+  for (( i = 1; i <= $#lines; i++ )); do
+    lines[$i]="$i -- ${lines[$i]}"
+  done
+fi
+# get the array of numbers only
+list=(${lines%% *})
+_description expl 'directory stack index'
+compadd "$expl[@]" -ld lines -V dirs -Q - "$list[@]" && ret=0
+[[ -z $compstate[list] ]] && compstate[list]=list && ret=0
+[[ -n $compstate[insert] ]] && compstate[insert]=menu && ret=0
+
+return ret
+#compdef popd
+
+# This just completes the numbers after +, showing the full directory list
+# with numbers. For - we do the same thing, but reverse the numbering (other
+# way round if pushdminus is set). Note that this function is also called
+# from _cd for cd and pushd.
+
 emulate -L zsh
 setopt extendedglob nonomatch
 
diff --git a/Completion/Builtins/_set b/Completion/Builtins/_set
index 297a15d3b..b96eb0efb 100644
--- a/Completion/Builtins/_set
+++ b/Completion/Builtins/_set
@@ -1,11 +1,9 @@
 #compdef set
 
-local prev="$words[CURRENT-1]" expl
+local prev="$words[CURRENT-1]"
 
 if [[ "$prev" = [-+]o ]]; then
-  _description expl 'zsh option'
-  compgen "$expl[@]" -o
+  _options
 elif [[ "$prev" = -A ]]; then
-  _description expl array
-  compgen "$expl[@]" -A
+  _arrays
 fi
diff --git a/Completion/Builtins/_stat b/Completion/Builtins/_stat
index 5a39e56e5..322f042ec 100644
--- a/Completion/Builtins/_stat
+++ b/Completion/Builtins/_stat
@@ -3,8 +3,7 @@
 local expl
 
 if [[ "$words[CURRENT-1]" = -[AH] ]]; then
-  _description expl array
-  compgen "$expl[@]" -A
+  _arrays
 else
   _description expl 'inode element'
   [[ "$PREFIX[1]" = + ]] &&
diff --git a/Completion/Builtins/_trap b/Completion/Builtins/_trap
index d6fc7b388..0f0209914 100644
--- a/Completion/Builtins/_trap
+++ b/Completion/Builtins/_trap
@@ -3,9 +3,9 @@
 local expl
 
 if [[ CURRENT -eq 2 ]]; then
-  _description expl command
-  compgen "$expl[@]" -c
+  compset -q
+  _normal
 else
   _description expl signal
-  compgen "$expl[@]" -k signals
+  compadd "$expl[@]" - "$signals[@]"
 fi
diff --git a/Completion/Builtins/_unhash b/Completion/Builtins/_unhash
index eb1787936..dfebd5399 100644
--- a/Completion/Builtins/_unhash
+++ b/Completion/Builtins/_unhash
@@ -4,19 +4,18 @@ local fl="$words[2]" ret=1 expl
 
 if [[ "$fl" = -*d* ]]; then
   _description expl 'named directory'
-  compgen "$expl[@]" -n && ret=0
+  compadd "$expl[@]" - "${(@k)nameddirs}" && ret=0
 fi
 if [[ "$fl" = -*a* ]]; then
   _description expl alias
-  compgen "$expl[@]" -a && ret=0
+  compadd "$expl[@]" - "${(@k)aliases}" && ret=0
 fi
 if [[ "$fl" = -*f* ]]; then
   _description expl 'shell function'
-  compgen "$expl[@]" -F && ret=0
+  compadd "$expl[@]" - "${(@k)functions}" && ret=0
 fi
 if [[ "$fl" != -* ]]; then
-  _description expl command
-  compgen "$expl[@]" -m && ret=0
+  _command_names -e && ret=0
 fi
 
 return ret
diff --git a/Completion/Builtins/_wait b/Completion/Builtins/_wait
index 17a030dad..68ca187e8 100644
--- a/Completion/Builtins/_wait
+++ b/Completion/Builtins/_wait
@@ -1,21 +1,10 @@
 #compdef wait
 
-# This uses two configuration keys:
-#
-#  ps_args
-#    This can be set to options of the ps(1) command that should be
-#    used when invoking it to get the pids to complete.
-#
-#  ps_listargs
-#    This defaults to the value of the `ps_args' key and defines
-#    options for the ps command that are to be used when creating
-#    the list to display during completion.
-
 local list ret=1 expl
 
-_description expl job
-compgen "$expl[@]" -P '%' -j && ret=0
-list=("${(@Mr:COLUMNS-1:)${(f)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
+_job -P '%' && ret=0
+
+list=("${(@M)${(f)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
 _description expl 'process ID'
 compadd "$expl[@]" -ld list - ${${${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *} && ret=0
 
diff --git a/Completion/Builtins/_which b/Completion/Builtins/_which
index d67af7316..30d20ab36 100644
--- a/Completion/Builtins/_which
+++ b/Completion/Builtins/_which
@@ -2,9 +2,13 @@
 
 local expl
 
-_description expl command
-compgen "$expl[@]" -c
-_description expl alias
-compgen "$expl[@]" -a
+_description expl 'external command'
+compadd "$expl[@]" "$@" - "${(k@)commands}" && ret=0
+_description expl 'builtin command'
+compadd "$expl[@]" "$@" - "${(k@)builtins[(R)^?disabled*]}" && ret=0
 _description expl 'shell function'
-compgen "$expl[@]" -F
+compadd "$expl[@]" "$@" - "${(k@)functions[(R)^?disabled*]}" && ret=0
+_description expl 'alias'
+compadd "$expl[@]" "$@" - "${(k@)raliases[(R)^?disabled*]}" && ret=0
+_description expl 'reserved word'
+compadd "$expl[@]" "$@" - "${(k@)reswords[(R)^?disabled*]}" && ret=0
diff --git a/Completion/Builtins/_zle b/Completion/Builtins/_zle
index 06e8fcad3..327d67c62 100644
--- a/Completion/Builtins/_zle
+++ b/Completion/Builtins/_zle
@@ -4,8 +4,8 @@ local expl
 
 if [[ "$words[2]" = -N && CURRENT -eq 3 ]]; then
   _description expl 'widget shell function'
-  compgen "$expl[@]" -F
+  compadd "$expl[@]" "$@" - "${(k@)functions[(R)^?disabled*]}" && ret=0
 else
   _description expl widget
-  compgen "$expl[@]" -b
+  compadd "$expl[@]" - "${(@k)zlewidgets}"
 fi
diff --git a/Completion/Builtins/_zmodload b/Completion/Builtins/_zmodload
index 429128517..a0d5987c4 100644
--- a/Completion/Builtins/_zmodload
+++ b/Completion/Builtins/_zmodload
@@ -4,10 +4,10 @@ local fl="$words[2]" expl
 
 if [[ "$fl" = -*(a*u|u*a)* || "$fl" = -*a* && CURRENT -ge 4 ]]; then
   _description expl 'builtin command'
-  compgen "$expl[@]" -B
+  compadd "$expl[@]" "$@" - "${(k@)builtins[(R)^?disabled*]}" && ret=0
 elif [[ "$fl" = -*u* ]]; then
   _description expl module
-  compadd "$expl[@]" - $(zmodload)
+  compadd "$expl[@]" - "${(@k)modules}"
 else
   _description expl 'module file'
   compadd "$expl[@]" - ${^module_path}/*.s[ol](N:t:r)
diff --git a/Completion/Commands/_bash_completions b/Completion/Commands/_bash_completions
index 5f3adc1e0..ee663fc30 100644
--- a/Completion/Commands/_bash_completions
+++ b/Completion/Commands/_bash_completions
@@ -30,7 +30,7 @@ local key=$KEYS[-1]
 case $key in
   '!') _main_complete _command_names
        ;;
-  '$') compgen -E
+  '$') compadd - "${(@k)parameters[(R)*export*]}"
        ;;
   '@') _main_complete _hosts
        ;;
diff --git a/Completion/Commands/_history_complete_word b/Completion/Commands/_history_complete_word
index f459046d2..1112339af 100644
--- a/Completion/Commands/_history_complete_word
+++ b/Completion/Commands/_history_complete_word
@@ -1,31 +1,108 @@
-#compdef -k complete-word \e/
+#compdef -K _history-complete-older complete-word \e/ _history-complete-newer complete-word \e,
+#
+# Complete words from the history
+#
+# by Adam Spiers, with help gratefully received from
+# Sven Wischnowsky and Bart Schaefer
+#
+# Available configuration keys:
+#
+#   history_list -- display lists of available matches
+#   history_stop -- prevent looping at beginning and end of matches
+#                   during menu-completion
+#   history_sort -- sort matches lexically (default is to sort by age)
+#   history_remove_all_dups --
+#                   remove /all/ duplicate matches rather than just
+#                   consecutives
+#
 
-local expl
+_history_complete_word () {
+  local expl direction
 
-if [[ -n "$compstate[old_list]" && -n "$compconfig[history_stop]" ]]; then
-  if [[ -z "$_hist_menu_end" &&
-        compstate[old_insert] -lt _hist_menu_length ]]; then
-    compstate[old_list]=keep
-    compstate[insert]=$((compstate[old_insert]+1))
+  if [[ $WIDGET = *newer ]]; then
+    direction=older
   else
-    _hist_menu_end=yes
-    if [[ "$compconfig[history_stop]" = verbose ]]; then
-      _message 'end of history reached'
-    else
-      compstate[old_list]=keep
-      compstate[insert]=_hist_menu_length
+    direction=newer
+  fi
+
+  [[ -z "$compconfig[history_list]" ]] && compstate[list]=''
+
+  if [[ -n "$compstate[old_list]" &&
+    ( -n "$compconfig[history_stop]" || "$compstate[insert]" = menu ) ]]; then
+    # array of matches is newest -> oldest (reverse of history order)
+    if [[ "$direction" == 'older' ]]; then
+      if [[ compstate[old_insert] -eq $_hist_menu_length ||
+            "$_hist_stop" == 'oldest' ]]; then
+        _hist_stop='oldest'
+        [[ "$compconfig[history_stop]" = verbose ]] &&
+          _message 'beginning of history reached'
+      elif [[ "$_hist_stop" == 'newest' ]]; then
+        zle -Rc
+        _history_complete_word_gen_matches
+      else
+        compstate[old_list]=keep
+        (( compstate[insert] = compstate[old_insert] + 1 ))
+      fi
+    elif [[ "$direction" == 'newer' ]]; then
+      if [[ compstate[old_insert] -eq 1 || "$_hist_stop" == 'newest' ]]; then
+        _hist_stop='newest'
+        [[ "$compconfig[history_stop]" = verbose ]] &&
+          _message 'end of history reached'
+      elif [[ "$_hist_stop" == 'oldest' ]]; then
+        zle -Rc
+        _history_complete_word_gen_matches
+      else
+        compstate[old_list]=keep
+        (( compstate[insert] = compstate[old_insert] - 1 ))
+      fi
     fi
+  else
+    _hist_stop=''
+    _hist_old_prefix="$PREFIX"
+    _history_complete_word_gen_matches
   fi
-else
-  if [[ -n "$compconfig[history_sort]" ]]; then
-    _description expl 'history word'
+
+  [[ -n "$compstate[nmatches]" ]]
+}
+
+_history_complete_word_gen_matches () {
+  if [[ -n "$compconfig[history_list]" ]]; then
+    if [[ -n "$compconfig[history_sort]" ]]; then
+      _description expl 'history word'
+    else
+      _description -V expl 'history word'
+    fi
   else
-    _description -V expl 'history word'
+    if [[ -n "$compconfig[history_sort]" ]]; then
+      expl=()
+    else
+      expl=('-V' '')
+    fi
   fi
-  compgen "$expl[@]" -Q -H 0 ''
-  if [[ -n "$compconfig[history_stop]" ]]; then
-    compstate[insert]=1
-    _hist_menu_length="$compstate[nmatches]"
-    _hist_menu_end=''
+
+  [[ -n "$_hist_stop" ]] && PREFIX="$_hist_old_prefix"
+
+  local rem_dups
+  if [[ -n "$compconfig[history_remove_all_dups]" ]]; then
+    rem_dups=''
+  else
+    rem_dups='-1'
   fi
-fi
+
+  compadd "$expl[@]" $rem_dups -Q - "${(@)historywords:#[\$'\"]*}"
+
+  _hist_menu_length="$compstate[nmatches]"
+
+  case "$direction" in 
+    newer)  compstate[insert]=$_hist_menu_length
+	    [[ -n "$_hist_stop" ]] && (( compstate[insert]-- ))
+            ;;
+    older)  compstate[insert]=1
+	    [[ -n "$_hist_stop" ]] && (( compstate[insert]++ ))
+            ;;
+  esac
+
+  [[ -n "$_hist_stop" ]] && _hist_stop=''
+}
+
+_history_complete_word "$@"
diff --git a/Completion/Commands/_read_comp b/Completion/Commands/_read_comp
index a32879b56..8a46d8af2 100644
--- a/Completion/Commands/_read_comp
+++ b/Completion/Commands/_read_comp
@@ -6,9 +6,9 @@
 # evaluate to generate the completions; unambiguous strings in the function
 # name are automatically completed.
 #
-# Else it is taken to be a set of arguments for compgen to generate a list
+# Else it is taken to be a set of arguments for compadd to generate a list
 # of choices.  The possibilities are the same as the flags for generating
-# completions given in the zshcompctl manual page.  Note the arguments are
+# completions given in the zshcompwid manual page.  Note the arguments are
 # verbatim:  include minus signs, spaces, quotes, etc.
 #
 # On subsequent calls, the same completion will be re-performed.  To
@@ -37,7 +37,7 @@ if [[ compstate[matcher] -gt 1 ||
   if [[ $_read_comp = _* ]]; then
     eval $_read_comp
   else
-    eval "compgen $_read_comp"
+    eval "compadd $_read_comp"
   fi
   return
 fi
@@ -154,5 +154,5 @@ zle -cR ''
 if [[ $str = _* ]]; then
   eval $str
 else
-  eval "compgen $str"
+  eval "compadd $str"
 fi
diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate
index 57b327e64..235e324f7 100644
--- a/Completion/Core/_approximate
+++ b/Completion/Core/_approximate
@@ -70,22 +70,6 @@ compadd() {
   fi
 }
 
-compgen() {
-  [[ "$*" != *-([a-zA-Z/]#|)U* &&
-     "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
-
-  if [[ "$PREFIX" = \~*/* ]]; then
-    PREFIX="${PREFIX%%/*}/(#a${_comp_correct})${PREFIX#*/}"
-  else
-    PREFIX="(#a${_comp_correct})$PREFIX"
-  fi
-  if [[ -n "$_correct_prompt" ]]; then
-    builtin compgen "$@" -X "$_correct_prompt" -J _correct
-  else
-    builtin compgen "$@" -J _correct
-  fi
-}
-
 # Now initialise our counter. We also set `compstate[matcher]'
 # to `-1'. This allows completion functions to use the simple
 # `[[ compstate[matcher] -gt 1 ]] && return' to avoid being
@@ -99,11 +83,6 @@ compstate[matcher]=-1
 
 _correct_prompt="${cfgps//\\%e/1}"
 
-# We also need to set `extendedglob' and make the completion
-# code behave as if globcomplete were set.
-
-setopt extendedglob
-
 [[ -z "$compstate[pattern_match]" ]] && compstate[pattern_match]='*'
 
 while [[ _comp_correct -le comax ]]; do
@@ -135,7 +114,7 @@ while [[ _comp_correct -le comax ]]; do
       compstate[force_list]=list
     fi
     compstate[matcher]="$compstate[total_matchers]"
-    unfunction compadd compgen
+    unfunction compadd
 
     return 0
   fi
@@ -147,6 +126,6 @@ while [[ _comp_correct -le comax ]]; do
 done
 
 compstate[matcher]="$compstate[total_matchers]"
-unfunction compadd compgen
+unfunction compadd
 
 return 1
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index 304a97828..72233a59b 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -9,13 +9,8 @@
 #
 #   local _set_options _unset_options
 #
-#   if zmodload -e parameter; then
-#     _set_options=(${(k)options[(R)on]})
-#     _unset_options=(${(k)options[(R)off]})
-#   else
-#     _set_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
-#     _unset_options=("${(@f)$({ unsetopt kshoptionprint; unsetopt } 2>/dev/null)}")
-#   fi
+#   _set_options=(${(k)options[(R)on]})
+#   _unset_options=(${(k)options[(R)off]})
 #
 # This is needed because completion functions may set options locally
 # which makes the output of setopt and unsetopt reflect a different
@@ -26,7 +21,7 @@ local comp post ret=1 _compskip
 
 typeset -U _lastdescr
 
-setopt localoptions nullglob rcexpandparam
+setopt localoptions nullglob rcexpandparam extendedglob
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
 
 # Special completion contexts after `~' and `='.
diff --git a/Completion/Core/_normal b/Completion/Core/_normal
index 085c738d2..79efaeb97 100644
--- a/Completion/Core/_normal
+++ b/Completion/Core/_normal
@@ -27,11 +27,7 @@ elif [[ "$command" == */* ]]; then
   cmd2="${command:t}"
 else
   cmd1="$command"
-  if zmodload -e parameter; then
-    cmd2="$commands[$command]"
-  else
-    cmd2=$(whence -p - $command)
-  fi
+  cmd2="$commands[$command]"
 fi
 
 # See if there are any matching pattern completions.
diff --git a/Completion/Core/_options b/Completion/Core/_options
index 356cd70db..0232db857 100644
--- a/Completion/Core/_options
+++ b/Completion/Core/_options
@@ -5,4 +5,5 @@
 local expl
 
 _description expl 'zsh option'
-compgen "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o
+compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \
+    "${(@k)options}"
diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters
index 34a8c3e9b..fdb786231 100644
--- a/Completion/Core/_parameters
+++ b/Completion/Core/_parameters
@@ -3,17 +3,11 @@
 # This should be used to complete parameter names if you need some of the
 # extra options of compadd. It completes only non-local parameters.
 
-setopt localoptions extendedglob
-
 local pars expl
 
 _description expl parameter
 
-if zmodload -e parameter; then
-  pars=( ${(k)parameters[(R)^*local*]} )
-else
-  pars=( ${${${(f)"$(typeset +)"}:#*local *}##* } )
-fi
+pars=( ${(k)parameters[(R)^*local*]} )
 
 compadd "$expl[@]" "$@" - $pars
 
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 9d44180c8..cbec82c8a 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -10,7 +10,7 @@ local nm=$compstate[nmatches] menu match matcher
 
 typeset -U prepaths exppaths
 
-setopt localoptions nullglob rcexpandparam extendedglob
+setopt localoptions nullglob rcexpandparam
 unsetopt markdirs globsubst shwordsplit nounset
 
 local sopt='-' gopt='' opt
@@ -110,36 +110,6 @@ orig="${PREFIX}${SUFFIX}"
    ( $#compstate[pattern_match] -ne 0 &&
      "${orig#\~}" != "${${orig#\~}:q}" ) ]] && menu=yes
 
-# We will first try normal completion called with `compgen', but only if we
-# weren't given a `-F', `-r', or `-R' option or we are in the string.
-
-if [[ -z "$suf" && $#ignore -eq 0 && $#remsfx -eq 0 &&
-      -z "$_comp_correct" ]]; then
-  # First build an array containing the `-W' option, if there is any and we
-  # want to use it. We don't want to use it if the string from the command line
-  # is a absolute path or relative to the current directory.
-
-  if [[ -z "$prepaths[1]" || "$pre[1]" = [~/] || "$pre" = (.|..)/* ]]; then
-    tmp1=()
-  else
-    tmp1=(-W "( $prepaths )")
-  fi
-
-  # Now call compgen.
-
-  if [[ -z "$gopt" ]]; then
-    compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" \
-            "$tmp1[@]" "$matcher[@]" $sopt
-  else
-    compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" \
-            "$tmp1[@]" "$matcher[@]" $sopt -g "$pats"
-  fi
-
-  # If this generated any matches, we don't want to do in-path completion.
-
-  [[ compstate[nmatches] -eq nm ]] || return 0
-fi
-
 # If given no `-F' option, we want to use `fignore'.
 
 (( $#ignore )) || ignore=(-F fignore)
diff --git a/Completion/Core/compinit b/Completion/Core/compinit
index ca9240f92..b3472ca0e 100644
--- a/Completion/Core/compinit
+++ b/Completion/Core/compinit
@@ -78,6 +78,10 @@ while [[ $# -gt 0 && $1 = -[dDf] ]]; do
   fi
 done
 
+# We need the parameter modules.
+
+zmodload -i parameter zleparameter
+
 # The associative array containing the definitions for the commands.
 # Definitions for patterns will be stored in the normal arrays `_patcomps'
 # and `_postpatcomps'.
diff --git a/Completion/Debian/_apt b/Completion/Debian/_apt
index e4593d54e..352dd3f2d 100644
--- a/Completion/Debian/_apt
+++ b/Completion/Debian/_apt
@@ -473,7 +473,7 @@ _apt-config () {
     -- \
     /$'shell\0'/ \
       \( \
-	/$'[^\0]#\0'/ :'compgen "$expl_shell_var[@]" -v' \
+	/$'[^\0]#\0'/ :'compadd "$expl_shell_var[@]" - "${(@k)parameters}' \
 	/$'[^\0]#\0'/ :'compadd "$expl_config_key[@]" - ${${(f)"$(apt-config dump 2>&1)"}% *}' \
       \) \# \| \
     /$'dump\0'/ \| \
diff --git a/Completion/User/_cvs b/Completion/User/_cvs
index 24a21f8be..ba732cb63 100644
--- a/Completion/User/_cvs
+++ b/Completion/User/_cvs
@@ -514,7 +514,7 @@ builtin functions _cvs_directories >&- ||
 _cvs_directories () {
   if [[ -d ${pref}CVS ]]; then
     _cvs_setup_direntries
-    (( $#entries )) && compgen "$@" -g "${(j:|:)${(@)entries:q}}"
+    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
   else
     _files "$@"
   fi
@@ -526,7 +526,7 @@ _cvs_files () {
   _cvs_setup_prefix
   if [[ -d ${pref}CVS ]]; then
     _cvs_setup_allentries
-    (( $#entries )) && compgen "$@" -g "${(j:|:)${(@)entries:q}}"
+    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
   else
     _files "$@"
   fi
@@ -538,7 +538,7 @@ _cvs_files_modified () {
   _cvs_setup_prefix
   if [[ -d ${pref}CVS ]]; then
     _cvs_setup_modentries
-    (( $#entries )) && compgen "$@" -g "${(j:|:)${(@)entries:q}}"
+    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
   else
     _files "$@"
   fi
@@ -572,8 +572,8 @@ _cvs_files_unmaintained () {
     omit=($_cvs_ignore_default ${entries:q} ${=cvsignore})
     [[ -r ~/.cvsignore ]] && omit=($omit $(<~/.cvsignore))
     [[ -r ${pref}.cvsignore ]] && omit=($omit $(<${pref}.cvsignore))
-    compgen "$@" -g '*~(*/|)('${(j:|:)omit}')(D)' ||
-    compgen "$@" -g '*~(*/|)('${(j:|:)${(@)entries:q}}')(D)' ||
+    _files "$@" -g '*~(*/|)('${(j:|:)omit}')(D)' ||
+    _files "$@" -g '*~(*/|)('${(j:|:)${(@)entries:q}}')(D)' ||
     _cvs_directories "$@"
   else
     _files "$@"
diff --git a/Completion/User/_gdb b/Completion/User/_gdb
index 4e21d7448..fc882ff90 100644
--- a/Completion/User/_gdb
+++ b/Completion/User/_gdb
@@ -47,8 +47,7 @@ else
   if [[ $#w -gt 1 ]]; then
     _files && ret=0
     _description expl 'process ID'
-    list=("${(F)${(@Mr:COLUMNS-1:)${(f)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${w[1]:t}}}
-")
+    list=("${(@M)${(f)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${w[1]:t}*}")
     compadd "$expl[@]" -ld list - ${${${(M)${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}:#*${w[1]:t}*}## #}%% *} && ret=0
 
     return ret
diff --git a/Completion/User/_man b/Completion/User/_man
index fd5702227..50445edf6 100644
--- a/Completion/User/_man
+++ b/Completion/User/_man
@@ -1,6 +1,6 @@
 #compdef man apropos whatis
 
-setopt localoptions rcexpandparam extendedglob
+setopt localoptions rcexpandparam
 
 local rep expl star approx
 
diff --git a/Completion/User/_mh b/Completion/User/_mh
index 3a2e53794..87ab8a18e 100644
--- a/Completion/User/_mh
+++ b/Completion/User/_mh
@@ -39,8 +39,7 @@ elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then
   _description expl 'MH folder'
   _path_files "$expl[@]" -W mhpath -/
 elif [[ "$prev" = -(editor|(whatnow|rmm|show|more)proc) ]]; then
-  _description expl command
-  compgen "$expl[@]" -c
+  _command_names -e
 elif [[ "$prev" = -file ]]; then
   _files
 elif [[ "$prev" = -(form|audit|filter) ]]; then
@@ -52,7 +51,7 @@ elif [[ "$prev" = -(form|audit|filter) ]]; then
   mhfpath=($mymhdir $mhlib)
 
   _description expl 'MH template file'
-  compgen "$expl[@]" -W mhfpath -g '*(.)'
+  _files "$expl[@]" -W mhfpath -g '*(.)'
 elif [[ "$prev" = -(no|)cc ]]; then
   _description expl 'CC address'
   compadd "$expl[@]" all to cc me
@@ -79,7 +78,7 @@ else
   compadd "$expl[@]" $(mark $foldnam 2>/dev/null | awk -F: '{ print $1 }') &&
       ret=0
   compadd "$expl[@]" reply next cur prev first last all unseen && ret=0
-  compgen "$expl[@]" -W folddir -g '<->' && ret=0
+  _files "$expl[@]" -W folddir -g '<->' && ret=0
 
   return ret
 fi
diff --git a/Completion/User/_nslookup b/Completion/User/_nslookup
index 6b2585f3d..7bf97a8ad 100644
--- a/Completion/User/_nslookup
+++ b/Completion/User/_nslookup
@@ -19,8 +19,6 @@
 # other characters than lower case letters, we try to call the function
 # `_nslookup_host'.
 
-setopt localoptions extendedglob
-
 local state expl ret=1 setopts
 
 setopts=(
diff --git a/Completion/User/_tar b/Completion/User/_tar
index 63838e83b..d779f6cf1 100644
--- a/Completion/User/_tar
+++ b/Completion/User/_tar
@@ -13,9 +13,6 @@
 #    tar itself (GNU tar)
 #  - Things like --directory=... are also completed correctly.
 
-emulate -LR zsh
-setopt extendedglob
-
 local _tar_cmd tf tmp del
 
 # First we collect in `_tar_cmd' single letter options describing what
diff --git a/Completion/User/_urls b/Completion/User/_urls
index 3b9afc4fd..1bc1ac76d 100644
--- a/Completion/User/_urls
+++ b/Completion/User/_urls
@@ -37,8 +37,6 @@
 #    name used by a user placing web pages within their home area.
 #    e.g. compconf urls_localhttp=www:/usr/local/apache/htdocs:public_html
 
-setopt localoptions extendedglob
-
 local ipre scheme host user hosts ret=1 expl
 local urls_path="${compconfig[urls_path]:-${ZDOTDIR:-$HOME}/.zsh/urls}"
 local localhttp_servername="${${(@s.:.)compconfig[urls_localhttp]}[1]}"
diff --git a/Completion/User/_users b/Completion/User/_users
index a054ccc66..6d0b1ce2f 100644
--- a/Completion/User/_users
+++ b/Completion/User/_users
@@ -10,4 +10,4 @@ _description expl user
 [[ "${(t)users}" = *array* ]] &&
     compadd "$expl[@]" "$@" - "$users[@]" && return 0
 
-compgen "$@" "$expl[@]" -u
+compadd "$@" "$expl[@]" - "${(@k)userdirs}"
diff --git a/Completion/User/_whereis b/Completion/User/_whereis
index 42fc30969..6f11b516c 100644
--- a/Completion/User/_whereis
+++ b/Completion/User/_whereis
@@ -1,6 +1,3 @@
 #compdef whereis
 
-local expl
-
-_description expl command
-compgen "$expl[@]" -m
+_command_names -e
diff --git a/Completion/User/_whois b/Completion/User/_whois
index 827ebe627..580529a72 100644
--- a/Completion/User/_whois
+++ b/Completion/User/_whois
@@ -1,7 +1,6 @@
 #compdef whois
 
 _whois () {
-  setopt localoptions extendedglob
   _whois_setup
   $_whois_comp
 }
diff --git a/Completion/X/_x_font b/Completion/X/_x_font
index f0b13c7a8..4ba21ddff 100644
--- a/Completion/X/_x_font
+++ b/Completion/X/_x_font
@@ -11,4 +11,4 @@ if (( ! $+_font_cache )); then
 fi
 
 _description expl font
-compgen -M 'r:|-=* r:|=*' "$expl[@]" "$@" -S '' -k _font_cache
+compadd -M 'r:|-=* r:|=*' "$expl[@]" "$@" -S '' - "$_font_cache[@]"
diff --git a/Completion/X/_x_window b/Completion/X/_x_window
index 118c7f131..65d2b72e2 100644
--- a/Completion/X/_x_window
+++ b/Completion/X/_x_window
@@ -1,7 +1,5 @@
 #autoload
 
-setopt localoptions extendedglob
-
 local list expl
 
 list=( "${(@)${(M@)${(@f)$(xwininfo -root -tree)}:#[ 	]#0x[0-9a-f]# \"*}##[ 	]#}" )
diff --git a/Completion/X/_xmodmap b/Completion/X/_xmodmap
index 29e584623..4e7a8bfc8 100644
--- a/Completion/X/_xmodmap
+++ b/Completion/X/_xmodmap
@@ -1,7 +1,5 @@
 #compdef xmodmap
 
-setopt localoptions extendedglob
-
 local state line ret=1
 typeset -A opt_args