summary refs log tree commit diff
path: root/Completion/Zsh/Context
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2002-03-04 08:53:41 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2002-03-04 08:53:41 +0000
commitf56ba813bb92b1d61be91cb39df620b37a5a0588 (patch)
tree6b7432b8e437bfbd92b7859e0c9e38dd11277f1d /Completion/Zsh/Context
parent10490ec499fff7b932f92a0b19c7e5343a24761d (diff)
downloadzsh-f56ba813bb92b1d61be91cb39df620b37a5a0588.tar.gz
zsh-f56ba813bb92b1d61be91cb39df620b37a5a0588.tar.xz
zsh-f56ba813bb92b1d61be91cb39df620b37a5a0588.zip
allow different sets of completion definitions selected with option -T to compdef; use this for parameter values and redirections (16755)
Diffstat (limited to 'Completion/Zsh/Context')
-rw-r--r--Completion/Zsh/Context/_default2
-rw-r--r--Completion/Zsh/Context/_in_vared2
-rw-r--r--Completion/Zsh/Context/_redirect16
-rw-r--r--Completion/Zsh/Context/_subscript2
-rw-r--r--Completion/Zsh/Context/_value83
5 files changed, 53 insertions, 52 deletions
diff --git a/Completion/Zsh/Context/_default b/Completion/Zsh/Context/_default
index 8176f392c..81744cdef 100644
--- a/Completion/Zsh/Context/_default
+++ b/Completion/Zsh/Context/_default
@@ -19,7 +19,7 @@ _files "$@" && return 0
 # allow completion to handle file names after any equals sign.
 
 if [[ -o magicequalsubst && "$PREFIX" = *\=* ]]; then
-  compstate[parameter]="${words[1]:t}-${PREFIX%%\=*}"
+  compstate[parameter]="${PREFIX%%\=*}"
   compset -P 1 '*='
   _value "$@"
 else
diff --git a/Completion/Zsh/Context/_in_vared b/Completion/Zsh/Context/_in_vared
index abd24dd95..03f6d404e 100644
--- a/Completion/Zsh/Context/_in_vared
+++ b/Completion/Zsh/Context/_in_vared
@@ -32,4 +32,4 @@ fi
 
 compstate[insert]="${compstate[insert]//tab /}"
 
-_contexts "$also"
+_dispatch comps "$also"
diff --git a/Completion/Zsh/Context/_redirect b/Completion/Zsh/Context/_redirect
index 6e02636da..5e454014b 100644
--- a/Completion/Zsh/Context/_redirect
+++ b/Completion/Zsh/Context/_redirect
@@ -1,3 +1,17 @@
 #compdef -redirect-
 
-_files
+# This searches for `<command-name>:<redir-op>' and `<redir-op>', where
+# `<redir-op>' is something like `<' or `2>'.
+
+local strs _comp_command1 _comp_command2
+
+_set_command
+
+strs=( "$compstate[redirect]" )
+
+if [[ -n "$_comp_command1" ]]; then
+  strs=( "${_comp_command1}:$strs[-1]" "$strs[@]" )
+  [[ -n "$_comp_command2" ]] && strs=( "${_comp_command2}:$strs[1]" "$strs[@]" )
+fi
+
+_dispatch -d redirs "$strs[@]"
diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript
index 9ea628fdb..0f1138e1a 100644
--- a/Completion/Zsh/Context/_subscript
+++ b/Completion/Zsh/Context/_subscript
@@ -113,5 +113,5 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
 
   return 1
 else
-  _contexts -math-
+  _dispatch comps -math-
 fi
diff --git a/Completion/Zsh/Context/_value b/Completion/Zsh/Context/_value
index 6ee8f4235..9d0acaa0e 100644
--- a/Completion/Zsh/Context/_value
+++ b/Completion/Zsh/Context/_value
@@ -1,19 +1,39 @@
-#compdef -value- -array-value-
+#compdef -value- -array-value- -T values -default-
 
-_value () {
-  # You can customize completion for different parameters by writing a
-  # function `_value:<name>', where <name> is the name of the parameter.
-  # When completing values of elements of associative arrays, we first
-  # search for a function `_value:<assoc>-<key>' and then for 
-  # `_value:<assoc>', so it's simple to define different functions
-  # for different keys or one function for a whole association.
+# You can customize completion for different parameters by writing
+# functions with the tag-line `#compdef -T value <name>'.
+# The function searches for the strings `<param-name>:<param-type>'
+# and `<param-name>'. If the line contains a command (as in `make foo=<TAB>')
+# the string `<command>:<param-name>:<param-type>' is also searched for.
 
-  if (( $+functions[_value:$compstate[parameter]] )); then
-    "_value:$compstate[parameter]" "$@"
-  elif (( $+functions[_value:${compstate[parameter]%%-*}] )); then
-    "_value:${compstate[parameter]%%-*}" "$@"
-  elif [[ "$compstate[parameter]" != *-* &&
-          "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
+if [[ "$service" != -default- ]]; then
+  local strs type
+
+  type="${(Pt)compstate[parameter]}"
+
+  if [[ -z "$type" ]]; then
+    if [[ "$compstate[parameter]" = *-* ]]; then
+      type=association-value
+    elif [[ "$compstate[context]" = value ]]; then
+      type=scalar
+    else
+      type=array
+    fi
+  fi
+
+  strs=( "${compstate[parameter]}:$type" "$compstate[parameter]" )
+
+  if [[ "$compstate[context]" != *value && -n "$_comp_command1" ]]; then
+    strs=( "${_comp_command1}:$^strs[@]" "$strs[@]" )
+    [[ -n "$_comp_command2" ]] &&
+        strs=( "${_comp_command2}:${(@)^strs[-2,-1]}" "$strs[@]" )
+  fi
+
+  _dispatch -d values "$strs[@]"
+else
+  if [[ "$compstate[parameter]" != *-* &&
+        "$compstate[context]" = *value &&
+        "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
     if (( CURRENT & 1 )); then
       _wanted association-keys expl 'association key' \
           compadd -k "$compstate[parameter]"
@@ -34,37 +54,4 @@ _value () {
       _default "$@"
     fi
   fi
-}
-
-_value:CPPFLAGS () {
-  compset -q
-  if compset -P '-I'; then
-    _files -/ "$@"
-  else
-    _default "$@"
-  fi
-}
-
-_value:LDFLAGS () {
-  compset -q
-  if compset -P '-L'; then
-    _files -/ "$@"
-  elif compset -P '-R'; then
-    compset -P '*:'
-    compset -S ':*'
-    _files -/ -S/ -r '\n\t\- /:' "$@"
-  else
-    _default "$@"
-  fi
-}
-
-_value:DISPLAY() { _x_display "$@" }
-
-_value:PRINTER() { _printers "$@" }
-_value:LPDEST() { _printers "$@" }
-
-_value:TERM() { _terminals "$@" }
-
-_value:TZ() { _time_zone "$@" }
-
-_value "$@"
+fi