about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Builtins/_pids33
-rw-r--r--Completion/Builtins/_zstyle7
-rw-r--r--Completion/Commands/_complete_help6
-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
10 files changed, 149 insertions, 51 deletions
diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids
index d3cf8a68e..5956ddb29 100644
--- a/Completion/Builtins/_pids
+++ b/Completion/Builtins/_pids
@@ -3,13 +3,21 @@
 # If given the `-m <pattern>' option, this tries to complete only pids
 # of processes whose command line match the `<pattern>'.
 
-local out list expl match desc listargs args
+local out list expl match desc listargs args all nm ret=1
 
 _tags processes || return 1
 
 if [[ "$1" = -m ]]; then
-  match="${2}*"
+  all=()
+  match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*[/[:blank:]]${2}*"
   shift 2
+elif [[ "$PREFIX$SUFFIX" = [0-9]# ]]; then
+  all=()
+  match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*"
+else
+  all=(-U)
+  match="*[[:blank:]]*[/[:blank:]]$PREFIX*$SUFFIX*"
+  nm="$compstate[nmatches]"
 fi
 
 zstyle -s ":completion:${curcontext}:processes" command args
@@ -20,9 +28,9 @@ if zstyle -T ":completion:${curcontext}:processes" verbose; then
   zstyle -s ":completion:${curcontext}:processes-list" command listargs
   (( $#listargs )) || listargs=( "$args[@]" )
   if [[ "$listargs" = "$args" ]]; then
-    list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+    list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#${~match}}")
   else
-    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#${~match}}")
   fi
   desc=(-ld list)
 else
@@ -30,5 +38,18 @@ else
 fi
 
 _wanted processes expl 'process ID' \
-    compadd "$@" "$desc[@]" - \
-        ${${${(M)${(f)"${out}"}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]#*${~match}}## #}%% *}
+    compadd "$@" "$desc[@]" "$all[@]" - \
+        ${${${(M)${(f)"${out}"}[2,-1]:#${~match}}## #}%% *} && ret=0
+
+if [[ -n "$all" ]]; then
+  zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu
+
+  case "$out" in
+  menu)   compstate[insert]=menu ;;
+  single) [[ $compstate[nmatches] -ne nm+1 ]] && compstate[insert]= ;;
+  *)      [[ ${#:-$PREFIX$SUFFIX} -gt ${#compstate[unambiguous]} ]] &&
+              compstate[insert]=menu ;;
+  esac
+fi
+
+return ret
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index b2bd1d5a8..995c8c6f2 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -31,12 +31,14 @@ styles=(
   group-name		 c:
   group-order		 c:tag
   groups		 c:_groups
+  guarded-completer      c:completer
   hidden		 c:bool
   hosts			 c:_hosts
   hosts-ports		 c:host-port
   users-hosts-ports	 c:user-host-port
   ignore-parents         c:ignorepar
   ignored-patterns	 c:
+  insert-ids             c:insert-ids
   insert-unambiguous	 c:bool
   last-prompt		 c:bool
   list			 c:listwhen
@@ -245,6 +247,11 @@ while [[ -n $state ]]; do
       _normal
       ;;
 
+    insert-ids)
+      _wanted values expl 'when to insert process IDs' \
+          compadd - menu single longer
+      ;;
+
     _*)
       ${=ostate}
       ;;
diff --git a/Completion/Commands/_complete_help b/Completion/Commands/_complete_help
index 6733111ff..b952480f8 100644
--- a/Completion/Commands/_complete_help
+++ b/Completion/Commands/_complete_help
@@ -9,9 +9,9 @@ _complete_help() {
 
   compadd() { return 1 }
   zstyle() {
-    local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
+    local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|all_labels|next_label)}% *}"
 
-    [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}"
+    [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|all_labels|next_label)}"
 
     if [[ "$help_sfuncs[$2]" != *${_f}* ||
           "$help_styles[${2}${_f}]" != *${3}* ]]; then
@@ -77,7 +77,7 @@ styles in context ${i}"
 }
 
 _help_sort_tags() {
-  local f="${${(@)${(@)funcstack[3,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
+  local f="${${(@)${(@)funcstack[3,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|all_labels|next_label)}% *}"
 
   if [[ "$help_funcs[$curcontext]" != *${f}* ||
         "$help_tags[${curcontext}${f}]" != *(${(j:|:)~argv})* ]]; then
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"