about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Completion/Core/_main_complete163
-rw-r--r--Completion/Core/_normal61
-rw-r--r--Completion/Core/compdump8
-rw-r--r--Completion/Core/compinit27
4 files changed, 130 insertions, 129 deletions
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index 285413726..7b2721e0b 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -69,79 +69,66 @@ for comp; do
   fi
 done
 
-# See which tags were or were not used.
-
-_used_tags=( "${(@)_tried_tags:#${(j:|:)~${(@)_failed_tags//\[/\\[}//\]/\\]}}" )
-_unused_tags=( "${(@)_offered_tags:#${(j:|:)~${(@)_used_tags//\[/\\[}//\]/\\]}}" )
-
-# Now call the post-functions.
-
-for post in "$comppostfuncs[@]"; do
-  "$post"
-done
-comppostfuncs=()
-
-_lastdescr=( "\`${(@)^_lastdescr:#}'" )
-
-[[ _last_nmatches -ge 0 && _last_nmatches -ne compstate[nmatches] ]] &&
-    _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" )
-
-if [[ "$compstate[insert]" = "$_saved_insert" ]]; then
-  if [[ -n "$_menu_style[(r)(yes|true|1|on)]" ||
-        ( -n "$_menu_style[(r)auto*]" &&
-          "$compstate[insert]" = automenu ) ]]; then
-    compstate[insert]=menu
-  elif [[ -n "$_menu_style[(r)auto*]" &&
-          "$compstate[insert]" != automenu ]]; then
-    compstate[insert]=automenu-unambiguous
-  elif [[ -n "$_menu_style[(r)(no|false|0|off)]" ]]; then
-    compstate[insert]=unambiguous
-  elif [[ -n "$_def_menu_style[(r)(yes|true|1|on)]" ||
-        ( -n "$_def_menu_style[(r)auto*]" &&
-          "$compstate[insert]" = automenu ) ]]; then
-    compstate[insert]=menu
-  elif [[ -n "$_def_menu_style[(r)auto*]" &&
-          "$compstate[insert]" != automenu ]]; then
-    compstate[insert]=automenu-unambiguous
-  elif [[ -n "$_def_menu_style[(r)(no|false|0|off)]" ]]; then
-    compstate[insert]=unambiguous
+if (( $compstate[nmatches] )); then
+  [[ _last_nmatches -ge 0 && _last_nmatches -ne compstate[nmatches] ]] &&
+      _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" )
+
+  if [[ "$compstate[insert]" = "$_saved_insert" ]]; then
+    if [[ -n "$_menu_style[(r)(yes|true|1|on)]" ||
+          ( -n "$_menu_style[(r)auto*]" &&
+            "$compstate[insert]" = automenu ) ]]; then
+      compstate[insert]=menu
+    elif [[ -n "$_menu_style[(r)auto*]" &&
+            "$compstate[insert]" != automenu ]]; then
+      compstate[insert]=automenu-unambiguous
+    elif [[ -n "$_menu_style[(r)(no|false|0|off)]" ]]; then
+      compstate[insert]=unambiguous
+    elif [[ -n "$_def_menu_style[(r)(yes|true|1|on)]" ||
+          ( -n "$_def_menu_style[(r)auto*]" &&
+            "$compstate[insert]" = automenu ) ]]; then
+      compstate[insert]=menu
+    elif [[ -n "$_def_menu_style[(r)auto*]" &&
+            "$compstate[insert]" != automenu ]]; then
+      compstate[insert]=automenu-unambiguous
+    elif [[ -n "$_def_menu_style[(r)(no|false|0|off)]" ]]; then
+      compstate[insert]=unambiguous
+    fi
   fi
-fi
-
-_menu_style=( "$_menu_style[@]" "$_def_menu_style[@]" )
-
-if [[ "$compstate[insert]" = *menu ]]; then
-  if [[ -n "$_menu_style[(r)no-select*]" ]]; then
-    unset SELECTMIN
-  else
-    sel=( "${(@M)_menu_style:#select*}" )
 
-    if (( $# )); then
-      local min=9999999 i num
-
-      for i in "$sel[@]"; do
-        if [[ "$i" = *\=* ]]; then
-	  num="${i#*\=}"
-	  [[ num -lt 0 ]] && num=0
-	else
-	  num=0
-	fi
-	[[ num -lt min ]] && min="$num"
-
-	(( min )) || break
-      done
-
-      SELECTMIN="$min"
+  _menu_style=( "$_menu_style[@]" "$_def_menu_style[@]" )
+
+  if [[ "$compstate[insert]" = *menu ]]; then
+    if [[ -n "$_menu_style[(r)no-select*]" ]]; then
+      unset SELECTMIN
+    else
+      sel=( "${(@M)_menu_style:#select*}" )
+
+      if (( $# )); then
+        local min=9999999 i num
+
+        for i in "$sel[@]"; do
+          if [[ "$i" = *\=* ]]; then
+  	    num="${i#*\=}"
+  	    [[ num -lt 0 ]] && num=0
+  	  else
+  	    num=0
+  	  fi
+  	  [[ num -lt min ]] && min="$num"
+  
+	  (( min )) || break
+        done
+
+        SELECTMIN="$min"
+      fi
     fi
   fi
-fi
-
-if [[ compstate[nmatches] -eq 0 &&
-      compstate[matcher] -eq compstate[total_matchers] &&
-      $#_lastdescr -ne 0 ]] &&
-   zstyle -s ":completion${curcontext}:warnings" format format; then
+elif [[ compstate[matcher] -eq compstate[total_matchers] &&
+        $#_lastdescr -ne 0 ]] &&
+     zstyle -s ":completion${curcontext}:warnings" format format; then
   local str
 
+  _lastdescr=( "\`${(@)^_lastdescr:#}'" )
+
   compstate[list]='list force'
   compstate[insert]=''
 
@@ -155,18 +142,34 @@ if [[ compstate[nmatches] -eq 0 &&
   compadd -UX "$format" -n ''
 fi
 
-_lastcomp=( "${(@kv)compstate}" )
-_lastcomp[completer]="$comp"
-_lastcomp[prefix]="$PREFIX"
-_lastcomp[suffix]="$SUFFIX"
-_lastcomp[iprefix]="$IPREFIX"
-_lastcomp[isuffix]="$ISUFFIX"
-_lastcomp[qiprefix]="$QIPREFIX"
-_lastcomp[qisuffix]="$QISUFFIX"
-_lastcomp[offered_tags]="${(j.:.)_offered_tags}"
-_lastcomp[tried_tags]="${(j.:.)_tried_tags}"
-_lastcomp[failed_tags]="${(j.:.)_failed_tags}"
-_lastcomp[unused_tags]="${(j.:.)_unused_tags}"
-_lastcomp[used_tags]="${(j.:.)_used_tags}"
+if [[ compstate[matcher] -eq compstate[total_matchers] ||
+      compstate[nmatches] -ne 0 ]]; then
+
+  # See which tags were or were not used.
+
+  _used_tags=( "${(@)_tried_tags:#${(j:|:)~${(@)_failed_tags//\[/\\[}//\]/\\]}}" )
+  _unused_tags=( "${(@)_offered_tags:#${(j:|:)~${(@)_used_tags//\[/\\[}//\]/\\]}}" )
+
+  # Now call the post-functions.
+
+  for post in "$comppostfuncs[@]"; do
+    "$post"
+  done
+  comppostfuncs=()
+
+  _lastcomp=( "${(@kv)compstate}" )
+  _lastcomp[completer]="$comp"
+  _lastcomp[prefix]="$PREFIX"
+  _lastcomp[suffix]="$SUFFIX"
+  _lastcomp[iprefix]="$IPREFIX"
+  _lastcomp[isuffix]="$ISUFFIX"
+  _lastcomp[qiprefix]="$QIPREFIX"
+  _lastcomp[qisuffix]="$QISUFFIX"
+  _lastcomp[offered_tags]="${(j.:.)_offered_tags}"
+  _lastcomp[tried_tags]="${(j.:.)_tried_tags}"
+  _lastcomp[failed_tags]="${(j.:.)_failed_tags}"
+  _lastcomp[unused_tags]="${(j.:.)_unused_tags}"
+  _lastcomp[used_tags]="${(j.:.)_used_tags}"
+fi
 
 return ret
diff --git a/Completion/Core/_normal b/Completion/Core/_normal
index f7d797aaa..a9e1dc5e4 100644
--- a/Completion/Core/_normal
+++ b/Completion/Core/_normal
@@ -26,11 +26,11 @@ else
   if [[ "$command[1]" == '=' ]]; then
     eval cmd1\=$command
     cmd2="$command[2,-1]"
-    curcontext="${curcontext}::${cmd1}:"
+    curcontext="${curcontext}::${cmd2}:"
   elif [[ "$command" == */* ]]; then
     cmd1="$command"
     cmd2="${command:t}"
-    curcontext="${curcontext}::${cmd1}:"
+    curcontext="${curcontext}::${cmd2}:"
   else
     cmd1="$command"
     cmd2="$commands[$command]"
@@ -41,17 +41,22 @@ fi
 # See if there are any matching pattern completions.
 
 if [[ "$_compskip" != (all|*patterns*) ]]; then
-  for i in "$_patcomps[@]"; do
-    pat="${i% *}"
-    val="${i#* }"
-    if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
-      "$val" && ret=0
-      if [[ "$_compskip" = *patterns* ]]; then
-        break
-      elif [[ "$_compskip" = all ]]; then
-        _compskip=''
-        return ret
-      fi
+  for i in "${(@)_patcomps[(K)$cmd1]}"; do
+    "$i" && ret=0
+    if [[ "$_compskip" = *patterns* ]]; then
+      break
+    elif [[ "$_compskip" = all ]]; then
+      _compskip=''
+      return ret
+    fi
+  done
+  for i in "${(@)_patcomps[(K)$cmd2]}"; do
+    "$i" && ret=0
+    if [[ "$_compskip" = *patterns* ]]; then
+      break
+    elif [[ "$_compskip" = all ]]; then
+      _compskip=''
+      return ret
     fi
   done
 fi
@@ -80,18 +85,24 @@ else
 fi
 
 if [[ "$_compskip" != (all|*patterns*) ]]; then
-  for i in "$_postpatcomps[@]"; do
-    pat="${i% *}"
-    val="${i#* }"
-    if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
-      _compskip=default
-      "$val" && ret=0
-      if [[ "$_compskip" = *patterns* ]]; then
-	break
-      elif [[ "$_compskip" = all ]]; then
-        _compskip=''
-        return ret
-      fi
+  for i in "${(@)_postpatcomps[(K)$cmd1]}"; do
+    _compskip=default
+    "$i" && ret=0
+    if [[ "$_compskip" = *patterns* ]]; then
+      break
+    elif [[ "$_compskip" = all ]]; then
+      _compskip=''
+      return ret
+    fi
+  done
+  for i in "${(@)_postpatcomps[(K)$cmd2]}"; do
+    _compskip=default
+    "$i" && ret=0
+    if [[ "$_compskip" = *patterns* ]]; then
+      break
+    elif [[ "$_compskip" = all ]]; then
+      _compskip=''
+      return ret
     fi
   done
 fi
diff --git a/Completion/Core/compdump b/Completion/Core/compdump
index 67b6e0865..97a181084 100644
--- a/Completion/Core/compdump
+++ b/Completion/Core/compdump
@@ -34,14 +34,14 @@ done  >> $_d_file
 print ")" >> $_d_file
 
 print "\n_patcomps=(" >> $_d_file
-for _d_f in "$_patcomps[@]"; do
-  print -r - "'${_d_f//\'/'\\''}'"
+for _d_f in "${(ok@)_patcomps}"; do
+  print -r - "'${_d_f//\'/'\\''}'" "'${_patcomps[$_d_f]//\'/'\\''}'"
 done >> $_d_file
 print ")" >> $_d_file
 
 print "\n_postpatcomps=(" >> $_d_file
-for _d_f in "$_postpatcomps[@]"; do
-  print -r - "'${_d_f//\'/'\\''}'"
+for _d_f in "${(ok@)_postpatcomps}"; do
+  print -r - "'${_d_f//\'/'\\''}'" "'${_postpatcomps[$_d_f]//\'/'\\''}'"
 done >> $_d_file
 print ")" >> $_d_file
 
diff --git a/Completion/Core/compinit b/Completion/Core/compinit
index 57c7a97e2..59aa137b1 100644
--- a/Completion/Core/compinit
+++ b/Completion/Core/compinit
@@ -79,12 +79,10 @@ while [[ $# -gt 0 && $1 = -[dDf] ]]; do
 done
 
 # The associative array containing the definitions for the commands.
-# Definitions for patterns will be stored in the normal arrays `_patcomps'
+# Definitions for patterns will be stored in the associations `_patcomps'
 # and `_postpatcomps'.
 
-typeset -gA _comps
-_patcomps=()
-_postpatcomps=()
+typeset -gA _comps _patcomps _postpatcomps
 
 # The associative array use to report information about the last
 # cmpletion to the outside.
@@ -212,17 +210,14 @@ compdef() {
         echo "$0: only one pattern allowed"
 	return 1
       fi
-      # Patterns are stored in strings like `c* foo', with a space
-      # between the pattern and the function name.
-
-      _patcomps=("$_patcomps[@]" "$1 $func")
+      _patcomps[$1]="$func"
       ;;
     postpattern)
       if [[ $# -gt 1 ]]; then
         echo "$0: only one pattern allowed"
 	return 1
       fi
-      _postpatcomps=("$_postpatcomps[@]" "$1 $func")
+      _postpatcomps[$1]="$func"
       ;;
     widgetkey)
       while [[ -n $1 ]]; do
@@ -283,15 +278,10 @@ compdef() {
     # Handle the `-d' option, deleting.
     case "$type" in
     pattern)
-      # Note the space.
-      for i; do
-        _patcomps=("${(@)_patcomps:#$i *}")
-      done
+      unset "_patcomps[$^@]"
       ;;
     postpattern)
-      for i; do
-        _postpatcomps=("${(@)_postpatcomps:#$i *}")
-      done
+      unset "_postpatcomps[$^@]"
       ;;
     key)
       # Oops, cannot do that yet.
@@ -300,10 +290,7 @@ compdef() {
       return 1
       ;;
     *)
-      # Deleting definitons for command is even simpler.
-      for i; do
-        unset "_comps[$i]"
-      done
+      unset "_comps[$^@]"
     esac
   fi
 }