summary refs log tree commit diff
path: root/Completion/Zsh
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2002-03-13 09:28:04 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2002-03-13 09:28:04 +0000
commit45f9a36216637075172d0bdf7ad8e18fad34c42e (patch)
tree8505f11011505b00e8cef1142b11c2b2e94e17e9 /Completion/Zsh
parent799b34d817a77244e9e371f6d5f1b01aa171214c (diff)
downloadzsh-45f9a36216637075172d0bdf7ad8e18fad34c42e.tar.gz
zsh-45f9a36216637075172d0bdf7ad8e18fad34c42e.tar.xz
zsh-45f9a36216637075172d0bdf7ad8e18fad34c42e.zip
remove that -T option to compdef again and instead use comma-separated sub-contexts both for function and style lookup (16819)
Diffstat (limited to 'Completion/Zsh')
-rw-r--r--Completion/Zsh/Command/_compdef54
-rw-r--r--Completion/Zsh/Context/_in_vared2
-rw-r--r--Completion/Zsh/Context/_redirect15
-rw-r--r--Completion/Zsh/Context/_subscript2
-rw-r--r--Completion/Zsh/Context/_value32
5 files changed, 59 insertions, 46 deletions
diff --git a/Completion/Zsh/Command/_compdef b/Completion/Zsh/Command/_compdef
index db4309642..48daa9e53 100644
--- a/Completion/Zsh/Command/_compdef
+++ b/Completion/Zsh/Command/_compdef
@@ -1,24 +1,37 @@
 #compdef compdef
 
-local state line expl list disp curcontext="$curcontext"
+local state line expl list disp curcontext="$curcontext" pat normal ret=1
+local args1 args2
 typeset -A opt_args
 
-_arguments -C -s -A "-*" -S \
-  '(-d)-a[make function autoloadable]' \
-  '(-d -p -P)-n[leave existing definitions intact]' \
-  "*-T[select type of completion function]:completion function type:($_comp_assocs)" \
+args2=()
+if (( ! ${words[2,-1][(I)[^-]*]} || ${words[(I)-[kK]]} )); then
+  args1=(
+    -A '-*'
+    '(-d)-a[make function autoloadable]'
+    '(-d)-n[leave existing definitions intact]'
+  )
+  args2=(
+     - d
+      '(-a -n)-d[delete]:*:completed command:->ccom'
+     - k
+      '-k[define widget and key binding]:completion function:->cfun:style:->style:*:key'
+     - K
+      '-K[define multiple widgets based on function]:*::: :->multi'
+  )
+else
+  args1=(
+    '-N[completion for named command]'
+  )
+fi
+
+_arguments -C -s -S \
+  "$args1[@]" \
+  '-p[completion for command matching pattern]' \
+  '-P[completion for command matching pattern]' \
   ':completion function:->cfun' \
-  '*:commands: _command_names' \
- - d \
-  '(-a -n)-d[delete]:*:completed command:->ccom' \
- - p \
-  '(-n)-p[completion for command matching pattern]:completion function:->cfun:pattern' \
- - P \
-  '(-n)-P[as -p for commands without own completion]:completion function:->cfun:pattern' \
- - k \
-  '-k[define widget and key binding]:completion function:->cfun:style:->style:*:key' \
- - K \
-  '-K[define multiple widgets based on function]:*::: :->multi' && return 0
+  '*:commands:->com' \
+  "$args2[@]" && return 0
 
 if [[ $state = multi ]]; then
   case $(( CURRENT % 3 )) in
@@ -30,6 +43,15 @@ if [[ $state = multi ]]; then
 fi
 
 case $state in
+  com)
+    pat="${words[(I)-[pP]]}"
+    normal="${words[(I)-N]}"
+    if (( pat && pat > normal )); then
+      _message -e patterns 'pattern'
+    else
+      _command_names
+    fi
+  ;;
   ccom)
     _wanted commands expl 'completed command' compadd -k _comps
   ;;
diff --git a/Completion/Zsh/Context/_in_vared b/Completion/Zsh/Context/_in_vared
index 03f6d404e..c3c8a20e2 100644
--- a/Completion/Zsh/Context/_in_vared
+++ b/Completion/Zsh/Context/_in_vared
@@ -32,4 +32,4 @@ fi
 
 compstate[insert]="${compstate[insert]//tab /}"
 
-_dispatch comps "$also"
+_dispatch "$also" "$also"
diff --git a/Completion/Zsh/Context/_redirect b/Completion/Zsh/Context/_redirect
index 5e454014b..b33e785ee 100644
--- a/Completion/Zsh/Context/_redirect
+++ b/Completion/Zsh/Context/_redirect
@@ -1,17 +1,16 @@
 #compdef -redirect-
 
-# This searches for `<command-name>:<redir-op>' and `<redir-op>', where
-# `<redir-op>' is something like `<' or `2>'.
-
-local strs _comp_command1 _comp_command2
+local strs _comp_command1 _comp_command2 _comp_command
 
 _set_command
 
-strs=( "$compstate[redirect]" )
+strs=( -default- )
 
 if [[ -n "$_comp_command1" ]]; then
-  strs=( "${_comp_command1}:$strs[-1]" "$strs[@]" )
-  [[ -n "$_comp_command2" ]] && strs=( "${_comp_command2}:$strs[1]" "$strs[@]" )
+  strs=( "${_comp_command1}" "$strs[@]" )
+  [[ -n "$_comp_command2" ]] &&
+      strs=( "${_comp_command2}" "$strs[@]" )
 fi
 
-_dispatch -d redirs "$strs[@]"
+_dispatch -redirect-,${compstate[redirect]},${_comp_command} \
+          -redirect-,{${compstate[redirect]},-default-},${^strs}
diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript
index 0f1138e1a..052848ffe 100644
--- a/Completion/Zsh/Context/_subscript
+++ b/Completion/Zsh/Context/_subscript
@@ -113,5 +113,5 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
 
   return 1
 else
-  _dispatch comps -math-
+  _dispatch -math- -math-
 fi
diff --git a/Completion/Zsh/Context/_value b/Completion/Zsh/Context/_value
index 9d0acaa0e..15732f22c 100644
--- a/Completion/Zsh/Context/_value
+++ b/Completion/Zsh/Context/_value
@@ -1,4 +1,4 @@
-#compdef -value- -array-value- -T values -default-
+#compdef -value- -array-value- -value-,-default-,-default-
 
 # You can customize completion for different parameters by writing
 # functions with the tag-line `#compdef -T value <name>'.
@@ -6,30 +6,20 @@
 # 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 [[ "$service" != -default- ]]; then
-  local strs type
+if [[ "$service" != -value-,* ]]; then
+  local strs ctx=
 
-  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]" )
+  strs=( -default- )
 
   if [[ "$compstate[context]" != *value && -n "$_comp_command1" ]]; then
-    strs=( "${_comp_command1}:$^strs[@]" "$strs[@]" )
+    ctx="${_comp_command}"
+    strs=( "${_comp_command1}" "$strs[@]" )
     [[ -n "$_comp_command2" ]] &&
-        strs=( "${_comp_command2}:${(@)^strs[-2,-1]}" "$strs[@]" )
+        strs=( "${_comp_command2}" "$strs[@]" )
   fi
 
-  _dispatch -d values "$strs[@]"
+  _dispatch -value-,${compstate[parameter]},$ctx \
+            -value-,{${compstate[parameter]},-default-},${^strs}
 else
   if [[ "$compstate[parameter]" != *-* &&
         "$compstate[context]" = *value &&
@@ -39,7 +29,9 @@ else
           compadd -k "$compstate[parameter]"
     else
       compstate[parameter]="${compstate[parameter]}-${words[CURRENT-1]}"
-      _value "$@"
+
+      _dispatch -value-,${compstate[parameter]}, \
+                -value-,{${compstate[parameter]},-default-},-default-
     fi
   else
     local pats