about summary refs log tree commit diff
path: root/Completion/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Core')
-rw-r--r--Completion/Core/.distfiles7
-rw-r--r--Completion/Core/_approximate12
-rw-r--r--Completion/Core/_complete10
-rw-r--r--Completion/Core/_correct4
-rw-r--r--Completion/Core/_expand2
-rw-r--r--Completion/Core/_files8
-rw-r--r--Completion/Core/_list4
-rw-r--r--Completion/Core/_normal2
-rw-r--r--Completion/Core/_parameters7
-rw-r--r--Completion/Core/_sep_parts2
-rw-r--r--Completion/Core/compinit34
11 files changed, 60 insertions, 32 deletions
diff --git a/Completion/Core/.distfiles b/Completion/Core/.distfiles
index 9a9e87d7c..c9362dccb 100644
--- a/Completion/Core/.distfiles
+++ b/Completion/Core/.distfiles
@@ -1,7 +1,8 @@
 DISTFILES_SRC='
     .distfiles
-    _approximate _closequotes _compalso _complete _correct _expand _files
-    _list _main_complete _match _menu _multi_parts _normal _oldlist _options
-    _parameters _path_files _sep_parts _set_options _unset_options
+    _approximate _compalso _complete _correct _expand
+    _files _list _main_complete _match _menu _multi_parts
+    _normal _oldlist _options _parameters _path_files
+    _sep_parts _set_options _unset_options
     compdump compinit compinstall
 '
diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate
index 1b40f7cbf..c63416901 100644
--- a/Completion/Core/_approximate
+++ b/Completion/Core/_approximate
@@ -1,9 +1,9 @@
 #autoload
 
 # This code will try to correct the string on the line based on the
-# strings generated for the context if `compconfig[correct]' is set.
-# These corrected strings will be shown in a list and one can
-# cycle through them as in a menucompletion or get the corrected prefix.
+# strings generated for the context. These corrected strings will be
+# shown in a list and one can cycle through them as in a menucompletion
+# or get the corrected prefix.
 #
 # Supported configuration keys:
 #
@@ -64,7 +64,7 @@
 local _comp_correct _correct_prompt comax
 local cfgacc cfgorig cfgps cfgins
 
-# Only if all global matchers hav been tried.
+# Only if all global matchers have been tried.
 
 [[ compstate[matcher] -ne compstate[total_matchers] ]] && return 1
 
@@ -153,7 +153,7 @@ compgen() {
 _comp_correct=1
 compstate[matcher]=-1
 
-_correct_prompt="${cfgps//\%e/1}"
+_correct_prompt="${cfgps//\\%e/1}"
 
 # We also need to set `extendedglob' and make the completion
 # code behave as if globcomplete were set.
@@ -188,7 +188,7 @@ while [[ _comp_correct -le comax ]]; do
   [[ "${#:-$PREFIX$SUFFIX}" -le _comp_correct+1 ]] && break
   (( _comp_correct++ ))
 
-  _correct_prompt="${cfgps//\%e/$_comp_correct}"
+  _correct_prompt="${cfgps//\\%e/$_comp_correct}"
 done
 
 compstate[matcher]="$compstate[total_matchers]"
diff --git a/Completion/Core/_complete b/Completion/Core/_complete
index 0f4d5ff4b..86ccc8c67 100644
--- a/Completion/Core/_complete
+++ b/Completion/Core/_complete
@@ -6,6 +6,15 @@
 
 local comp name
 
+# If we have a user-supplied context name, use only that.
+
+if [[ -n "$compcontext" ]]; then
+  comp="$_comps[$compcontext]"
+  [[ -z "$comp" ]] || "$comp"
+
+  return
+fi
+
 # An entry for `-first-' is the replacement for `compctl -T'
 # Completion functions may set `_compskip' to any value to make the 
 # main loops stop calling other completion functions.
@@ -20,6 +29,7 @@ if [[ ! -z "$comp" ]]; then
   fi
 fi
 
+
 # For arguments and command names we use the `_normal' function.
 
 if [[ "$compstate[context]" = command ]]; then
diff --git a/Completion/Core/_correct b/Completion/Core/_correct
index 35ab01cf1..c9c3d999c 100644
--- a/Completion/Core/_correct
+++ b/Completion/Core/_correct
@@ -1,8 +1,8 @@
 #autoload
 
-# This is mainly a wrapper around the more general `_approximate.
+# This is mainly a wrapper around the more general `_approximate'.
 # By setting `compstate[pattern_match]' to something unequal to `*' and
-# then calling `_approximate, we get only corrections, not all strings
+# then calling `_approximate', we get only corrections, not all strings
 # with the corrected prefix and something after it.
 #
 # Supported configuration keys are the same as for `_approximate', only
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index 9172b6cbf..aca3839d4 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -132,7 +132,7 @@ else
   if [[ -z "$compconfig[expand_prompt]" ]]; then
     compadd -UQ $group _expand - "$exp[@]"
   else
-    compadd -UQ -X "${compconfig[expand_prompt]//\%o/$word}" \
+    compadd -UQ -X "${compconfig[expand_prompt]//\\%o/$word}" \
             $group _expand - "$exp[@]"
   fi
   [[ "$compconfig[expand_menu]" != *last* &&
diff --git a/Completion/Core/_files b/Completion/Core/_files
index 506ddbc8e..b6349a8c5 100644
--- a/Completion/Core/_files
+++ b/Completion/Core/_files
@@ -1,7 +1,7 @@
 #autoload
 
 # Utility function for completing files of a given type or any file.
-# In many cases you will want to call this one instead of _path_files().
+# In many cases you will want to call this one instead of `_path_files'.
 
 local nm=$compstate[nmatches] ret=1
 
@@ -12,9 +12,9 @@ if [[ $# -ne 0 && compstate[nmatches] -eq nm ]]; then
 
   # We didn't get any matches for those types of files described by
   # the `-g' or `-/' option. Now we try it again accepting all files.
-  # First we get those options that we have to use even if then. If
-  # we find out that the `-f' option was given, we already accepted
-  # all files and give up immediatly.
+  # First we get those options that we have to use even then. If we
+  # find out that the `-f' option was given, we already accepted all
+  # files and give up immediatly.
 
   opts=()
   while getopts "P:S:W:F:J:V:X:f/g:" opt; do
diff --git a/Completion/Core/_list b/Completion/Core/_list
index 099c6bc7b..0d5651c23 100644
--- a/Completion/Core/_list
+++ b/Completion/Core/_list
@@ -1,8 +1,8 @@
 #autoload
 
 # This completer function makes the other completer functions used
-# insert possible completions only after once the list has been
-# shown.
+# insert possible completions only after the list has been shown at
+# least once.
 #
 # Configuration keys:
 #
diff --git a/Completion/Core/_normal b/Completion/Core/_normal
index 98337eae5..ed7243bb1 100644
--- a/Completion/Core/_normal
+++ b/Completion/Core/_normal
@@ -3,7 +3,7 @@
 local comp command cmd1 cmd2 pat val name i ret=1
 
 # Completing in command position? If not we set up `cmd1' and `cmd2' as
-# two strings we have search in the completion definition arrays (e.g.
+# two strings we have to search in the completion definition arrays (e.g.
 # a path and the last path name component).
 
 command="$words[1]"
diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters
index 0e8c548f7..d9d8a38b2 100644
--- a/Completion/Core/_parameters
+++ b/Completion/Core/_parameters
@@ -1,8 +1,7 @@
 #autoload
 
 # This should be used to complete parameter names if you need some of the
-# extra options of compadd. It first tries to complete only non-local
-# parameters. All arguments are given to compadd.
+# extra options of compadd. It completes only non-local parameters. All
+# arguments are given to compadd.
 
-compadd "$@" - "${(@)${(@)${(@)${(@f)$(typeset)}:#*local *\=*}%%\=*}##* }" ||
-    compadd "$@" - "${(@)${(@)${(@f)$(typeset)}%%\=*}##* }"
+compadd "$@" - "${(@)${(@)${(@)${(@f)$(typeset)}:#*local *\=*}%%\=*}##* }"
diff --git a/Completion/Core/_sep_parts b/Completion/Core/_sep_parts
index b906a3042..6f2595120 100644
--- a/Completion/Core/_sep_parts
+++ b/Completion/Core/_sep_parts
@@ -9,7 +9,7 @@
 #
 #  _sep_parts '(foo bar)' @ hosts
 #
-# This will make this function complete the strings `foo' and `bar'
+# This will make this function complete the strings `foo' and `bar'.
 # If the string on the line contains a `@', the substring after it
 # will be completed from the array `hosts'. Of course more arrays
 # may be given, each preceded by another separator string.
diff --git a/Completion/Core/compinit b/Completion/Core/compinit
index 77f918502..af2467bec 100644
--- a/Completion/Core/compinit
+++ b/Completion/Core/compinit
@@ -2,7 +2,7 @@
 # functions and aliases. Everything else is split into different files that
 # will automatically be made autoloaded (see the end of this file).
 # The names of the files that will be considered for autoloading have to
-# start with an underscores (like `_setopt).
+# start with an underscores (like `_setopt').
 # The first line of these files will be read and has to say what should be
 # done with its contents:
 #
@@ -50,11 +50,11 @@
 _i_fdir=''
 _i_dumpfile=''
 _i_autodump=0
-while [[ $1 = -[df] ]]; do
+while [[ $# -gt 0 && $1 = -[df] ]]; do
   if [[ "$1" = -d ]]; then
     _i_autodump=1
     shift
-    if [[ -n "$1" && "$1" != -[df] ]]; then
+    if [[ $# -gt 0 && "$1" != -[df] ]]; then
       _i_dumpfile="$1"
       shift
     fi
@@ -91,13 +91,31 @@ elif [[ -n $_i_fdir ]]; then
   # We were told what directory to use.
   compconfig[dumpfile]="$_i_fdir/compinit.dump"
 else
-  # Now we're stuck, but we'd better do something.
-  compconfig[dumpfile]="$HOME/.compinit.dump"
+  compconfig[dumpfile]=''
 fi
 
-compconfig[correct_accept]=2n
-compconfig[correct_prompt]='correct to:'
-compconfig[completer]=_complete
+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
+
+(( ${+compconfig[correct_accept]} )) || compconfig[correct_accept]=2n
+(( ${+compconfig[correct_prompt]} )) ||
+  compconfig[correct_prompt]='correct to:'
+(( ${+compconfig[completer]} )) || compconfig[completer]=_complete
 
 # This function is used to register or delete completion functions. For
 # registering completion functions, it is invoked with the name of the