From f56ba813bb92b1d61be91cb39df620b37a5a0588 Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Mon, 4 Mar 2002 08:53:41 +0000 Subject: allow different sets of completion definitions selected with option -T to compdef; use this for parameter values and redirections (16755) --- Completion/Zsh/Command/_compdef | 1 + Completion/Zsh/Context/_default | 2 +- Completion/Zsh/Context/_in_vared | 2 +- Completion/Zsh/Context/_redirect | 16 +++++++- Completion/Zsh/Context/_subscript | 2 +- Completion/Zsh/Context/_value | 83 +++++++++++++++++---------------------- 6 files changed, 54 insertions(+), 52 deletions(-) (limited to 'Completion/Zsh') diff --git a/Completion/Zsh/Command/_compdef b/Completion/Zsh/Command/_compdef index eb1a2ebb6..db4309642 100644 --- a/Completion/Zsh/Command/_compdef +++ b/Completion/Zsh/Command/_compdef @@ -6,6 +6,7 @@ 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)" \ ':completion function:->cfun' \ '*:commands: _command_names' \ - d \ 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 `:' and `', where +# `' 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:', where is the name of the parameter. - # When completing values of elements of associative arrays, we first - # search for a function `_value:-' and then for - # `_value:', 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 '. +# The function searches for the strings `:' +# and `'. If the line contains a command (as in `make foo=') +# the string `::' 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 -- cgit 1.4.1