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/_all_labels2
-rw-r--r--Completion/Core/_approximate9
-rw-r--r--Completion/Core/_expand32
-rw-r--r--Completion/Core/_ignored58
-rw-r--r--Completion/Core/_main_complete16
-rw-r--r--Completion/Core/_prefix30
-rw-r--r--Completion/Core/_setup7
7 files changed, 112 insertions, 42 deletions
diff --git a/Completion/Core/_all_labels b/Completion/Core/_all_labels
index 72d9d0317..f85478cb5 100644
--- a/Completion/Core/_all_labels
+++ b/Completion/Core/_all_labels
@@ -32,7 +32,7 @@ while comptags "-A$prev" "$1" curtag spec; do
     _description "$gopt" "${curtag%:*}" "$2" "$descr"
     curtag="${curtag%:*}"
 
-    "$4" "${(P@)2}" "${(@)argv[5,-1]}"
+    "$4" "${(P@)2}" "${(@)argv[5,-1]}" && ret=0
   else
     _description "$gopt" "$curtag" "$2" "$3"
 
diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate
index 840c1729a..47fc9ce23 100644
--- a/Completion/Core/_approximate
+++ b/Completion/Core/_approximate
@@ -13,7 +13,14 @@
 local _comp_correct _correct_expl comax cfgacc redef
 local oldcontext="${curcontext}" opm="$compstate[pattern_match]"
 
-zstyle -s ":completion:${curcontext}:" max-errors cfgacc || cfgacc='2 numeric'
+if [[ "$1" = -a* ]]; then
+  cfgacc="${1[3,-1]}"
+elif [[ "$1" = -a ]]; then
+  cfgacc="$2"
+else
+  zstyle -s ":completion:${curcontext}:" max-errors cfgacc ||
+      cfgacc='2 numeric'
+fi
 
 # Get the number of errors to accept.
 
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index f75c626d3..985f21899 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -11,7 +11,12 @@ setopt localoptions nullglob
 
 [[ _matcher_num -gt 1 ]] && return 1
 
-local exp word sort expr expl subd suf=" "
+local exp word sort expr expl subd suf=" " force opt
+
+(( $# )) &&
+    while getopts gsco opt; do
+      force="$force$opt"
+    done
 
 if [[ "$funcstack[2]" = _prefix ]]; then
   word="$IPREFIX$PREFIX$SUFFIX"
@@ -21,8 +26,9 @@ fi
 
 # First, see if we should insert all *completions*.
 
-if zstyle -s ":completion:${curcontext}:" completions expr &&
-   [[ "${(e):-\$[$expr]}" -eq 1 ]]; then
+if [[ "$force" = *c* ]] ||
+   { zstyle -s ":completion:${curcontext}:" completions expr &&
+     [[ "${(e):-\$[$expr]}" -eq 1 ]] }; then
   compstate[insert]=all
   return 1
 fi
@@ -35,9 +41,10 @@ exp=("$word")
 # changes quoted spaces, tabs, and newlines into spaces and protects
 # this function from aborting on parse errors in the expansion.
 
-if { zstyle -s ":completion:${curcontext}:" substitute expr ||
-     { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
-       [[ "${(e):-\$[$expr]}" -eq 1 ]]; then
+if [[ "$force" = *s* ]] ||
+   { { zstyle -s ":completion:${curcontext}:" substitute expr ||
+       { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
+         [[ "${(e):-\$[$expr]}" -eq 1 ]] }; then
   exp=( ${(f)"$(print -lR - ${(e)exp//\\[ 	
 ]/ })"} ) 2>/dev/null
 else
@@ -52,9 +59,10 @@ subd=("$exp[@]")
 
 # Now try globbing.
 
-{ zstyle -s ":completion:${curcontext}:" glob expr ||
-  { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
-    [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
+[[ "$force" = *g* ]] ||
+  { { zstyle -s ":completion:${curcontext}:" glob expr ||
+      { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
+        [[ "${(e):-\$[$expr]}" -eq 1 ]] } &&
     exp=( ${~exp} )
 
 # If we don't have any expansions or only one and that is the same
@@ -67,8 +75,10 @@ subd=("$exp[@]")
 # With subst-globs-only we bail out if there were no glob expansions,
 # regardless of any substitutions
 
-zstyle -s ":completion:${curcontext}:" subst-globs-only expr &&
-    [[ "${(e):-\$[$expr]}" -eq 1 && "$subd" = "$exp"(|\(N\)) ]] && return 1
+[[ "$force" = *o* ]] ||
+  { zstyle -s ":completion:${curcontext}:" subst-globs-only expr &&
+      [[ "${(e):-\$[$expr]}" -eq 1 ]] } && 
+        [[ "$subd" = "$exp"(|\(N\)) ]] && return 1
 
 # Now add as matches whatever the user requested.
 
diff --git a/Completion/Core/_ignored b/Completion/Core/_ignored
index 4046f4c2d..61d6d3ea5 100644
--- a/Completion/Core/_ignored
+++ b/Completion/Core/_ignored
@@ -2,30 +2,54 @@
 
 # Use ignored matches.
 
-(( $compstate[ignored] )) || return 1
+[[ _matcher_num -gt 1 || $compstate[ignored] -eq 0 ]] && return 1
 
-local comp i _comp_no_ignore=yes tmp expl
+local comp _comp_no_ignore=yes tmp expl \
+      _completer _completer_num _matcher _matchers _matcher_num
 
 zstyle -a ":completion:${curcontext}:" completer comp ||
   comp=( "${(@)_completers[1,_completer_num-1][(R)_ignored(|:*),-1]}" )
 
-for i in "$comp[@]"; do
-  if [[ "$i" != _ignored ]] && "$i"; then
-    if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
-       [[ $compstate[old_list] != shown && $compstate[nmatches] -eq 1 ]]; then
-      case "$tmp" in
-      show) compstate[insert]='' compstate[list]='list force' tmp='' ;;
-      menu)
-        compstate[insert]=menu
-        _description original expl original    
-        compadd "$expl[@]" -S '' - "$PREFIX$SUFFIX"
-        ;;
-      *) tmp='' ;;
-      esac
-    fi
+_completer_num=1
 
-    return 0
+for tmp in "$comp[@]"; do
+  if [[ "$tmp" = *:-* ]]; then
+    _completer="${${tmp%:*}[2,-1]//_/-}${tmp#*:}"
+    tmp="${tmp%:*}"
+  elif [[ $tmp = *:* ]]; then
+    _completer="${tmp#*:}"
+    tmp="${tmp%:*}"
+  else
+    _completer="${tmp[2,-1]//_/-}"
   fi
+  curcontext="${curcontext/:[^:]#:/:${_completer}:}"
+
+  zstyle -a ":completion:${curcontext}:" matcher-list _matchers ||
+      _matchers=( '' )
+
+  _matcher_num=1
+  for _matcher in "$_matchers[@]"; do
+    if [[ "$tmp" != _ignored ]] && "$tmp"; then
+      if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
+         [[ $compstate[old_list] != shown &&
+            $compstate[nmatches] -eq 1 ]]; then
+        case "$tmp" in
+        show) compstate[insert]='' compstate[list]='list force' tmp='' ;;
+        menu)
+          compstate[insert]=menu
+          _description original expl original    
+          compadd "$expl[@]" -S '' - "$PREFIX$SUFFIX"
+          ;;
+        esac
+      fi
+
+      return 0
+    fi
+
+    (( _matcher_num++ ))
+  done
+
+  (( _completer_num++ ))
 done
 
 return 1
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index c4672b61f..f079e38e2 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -20,14 +20,15 @@ setopt localoptions nullglob rcexpandparam extendedglob
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
 
 local func funcs ret=1 tmp _compskip format nm \
-      _completers _completer _completer_num curtag \
+      _completers _completer _completer_num curtag _comp_force_list \
       _matchers _matcher _matcher_num _comp_tags _comp_mesg \
       context state line opt_args val_args curcontext="$curcontext" \
       _last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \
       _saved_exact="${compstate[exact]}" \
       _saved_lastprompt="${compstate[last_prompt]}" \
       _saved_list="${compstate[list]}" \
-      _saved_insert="${compstate[insert]}"
+      _saved_insert="${compstate[insert]}" \
+      _saved_colors="$ZLS_COLORS"
 
 typeset -U _lastdescr _comp_ignore
 
@@ -203,12 +204,11 @@ elif [[ nm -eq 0 &&
   fi
 fi
 
-if zstyle -s ":completion:${curcontext}:" force-list tmp &&
-   [[ "$compstate[list]" = *list* && 
-      ( "$tmp" = always ||
-        ( "$tmp" = [0-9]## && nm -ge tmp ) ) ]]; then
-  compstate[list]="$compstate[list] force"
-fi
+[[ "$_comp_force_list" = always ||
+   ( "$_comp_force_list" = ?*  && nm -ge _comp_force_list ) ]] &&
+    compstate[list]="$compstate[list] force"
+
+[[ "$compstate[old_list]" = keep ]] && ZLS_COLORS="$_saved_colors"
 
 # Now call the post-functions.
 
diff --git a/Completion/Core/_prefix b/Completion/Core/_prefix
index f6e3b0831..18e6e3270 100644
--- a/Completion/Core/_prefix
+++ b/Completion/Core/_prefix
@@ -2,9 +2,10 @@
 
 # Try to ignore the suffix. A bit like e-o-c-prefix.
 
-[[ -n "$SUFFIX" ]] || return 1
+[[ _matcher_num -gt 1 || -z "$SUFFIX" ]] && return 1
 
-local comp i
+local comp curcontext="$curcontext" tmp \
+      _completer _completer_num _matcher _matchers _matcher_num
 
 zstyle -a ":completion:${curcontext}:" completer comp ||
   comp=( "${(@)_completers[1,_completer_num-1][(R)_prefix(|:*),-1]}" )
@@ -16,8 +17,29 @@ else
 fi
 SUFFIX=''
 
-for i in "$comp[@]"; do
-  [[ "$i" != _prefix ]] && "$i" && return 0
+_completer_num=1
+
+for tmp in "$comp[@]"; do
+  if [[ "$tmp" = *:-* ]]; then
+    _completer="${${tmp%:*}[2,-1]//_/-}${tmp#*:}"
+    tmp="${tmp%:*}"
+  elif [[ $tmp = *:* ]]; then
+    _completer="${tmp#*:}"
+    tmp="${tmp%:*}"
+  else
+    _completer="${tmp[2,-1]//_/-}"
+  fi
+  curcontext="${curcontext/:[^:]#:/:${_completer}:}"
+
+  zstyle -a ":completion:${curcontext}:" matcher-list _matchers ||
+      _matchers=( '' )
+
+  _matcher_num=1
+  for _matcher in "$_matchers[@]"; do
+    [[ "$tmp" != _prefix ]] && "$tmp" && return 0
+    (( _matcher_num++ ))
+  done
+  (( _completer_num++ ))
 done
 
 return 1
diff --git a/Completion/Core/_setup b/Completion/Core/_setup
index ed7307e69..6d5f09ab3 100644
--- a/Completion/Core/_setup
+++ b/Completion/Core/_setup
@@ -59,3 +59,10 @@ if zstyle -a ":completion:${curcontext}:$1" menu val; then
 else
   _last_nmatches=-1
 fi
+
+[[ "$_comp_force_list" != always ]] &&
+  zstyle -s ":completion:${curcontext}:$1" force-list val &&
+    [[ "$val" = always ||
+       ( "$val" = [0-9]## &&
+         ( -z "$_comp_force_list" || _comp_force_list -lt val ) ) ]] &&
+    _comp_force_list="$val"