1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-11 20:31:11 +01:00

allow arguments to be given to functions used by compdef (actually, the strings are eval'uated, so this should be powerful enough) (16472)

This commit is contained in:
Sven Wischnowsky 2002-01-21 16:13:15 +00:00
parent 4f6493aff1
commit f463b09b13
6 changed files with 40 additions and 15 deletions

View file

@ -1,3 +1,11 @@
2002-01-21 Sven Wischnowsky <wischnow@zsh.org>
* 16472: Completion/Base/Completer/_complete,
Completion/Base/Core/_normal, Completion/Base/Utility/_contexts,
Completion/Unix/Command/_su, Doc/Zsh/compsys.yo: allow
arguments to be given to functions used by compdef (actually,
the strings are eval'uated, so this should be powerful enough)
2002-01-17 Oliver Kiddle <opk@zsh.org> 2002-01-17 Oliver Kiddle <opk@zsh.org>
* 16464: Completion/Base/Widget/_complete_debug, * 16464: Completion/Base/Widget/_complete_debug,

View file

@ -85,7 +85,7 @@ if [[ -n "$compcontext" ]]; then
ccarray[3]="$compcontext" ccarray[3]="$compcontext"
comp="$_comps[$compcontext]" comp="$_comps[$compcontext]"
[[ -z "$comp" ]] || "$comp" [[ -n "$comp" ]] && eval "$comp"
fi fi
return return
@ -94,10 +94,10 @@ fi
# An entry for `-first-' is the replacement for `compctl -T' # An entry for `-first-' is the replacement for `compctl -T'
comp="$_comps[-first-]" comp="$_comps[-first-]"
if [[ ! -z "$comp" ]]; then if [[ -n "$comp" ]]; then
service="${_services[-first-]:--first-}" service="${_services[-first-]:--first-}"
ccarray[3]=-first- ccarray[3]=-first-
"$comp" && ret=0 eval "$comp" && ret=0
if [[ "$_compskip" = all ]]; then if [[ "$_compskip" = all ]]; then
_compskip= _compskip=
return ret return ret
@ -135,8 +135,8 @@ else
fi fi
comp="$_comps[-default-]" comp="$_comps[-default-]"
fi fi
[[ -z "$comp" ]] || [[ -n "$comp" ]] &&
service="${_services[-default-]:--default-}" && "$comp" && ret=0 service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
fi fi
_compskip= _compskip=

View file

@ -19,7 +19,7 @@ if [[ CURRENT -eq 1 ]]; then
curcontext="${curcontext%:*:*}:-command-:" curcontext="${curcontext%:*:*}:-command-:"
comp="$_comps[-command-]" comp="$_comps[-command-]"
[[ -z "$comp" ]] || "$comp" && ret=0 [[ -n "$comp" ]] && eval "$comp" && ret=0
return ret return ret
else else
@ -86,7 +86,7 @@ service="${_services[$cmd1]:-$cmd1}"
if [[ -n "$comp" ]]; then if [[ -n "$comp" ]]; then
_compskip=patterns _compskip=patterns
"$comp" && ret=0 eval "$comp" && ret=0
[[ "$_compskip" = (all|*patterns*) ]] && return ret [[ "$_compskip" = (all|*patterns*) ]] && return ret
elif [[ "$_compskip" != *default* ]]; then elif [[ "$_compskip" != *default* ]]; then
name=-default- name=-default-
@ -121,7 +121,7 @@ if [[ "$_compskip" != (all|*patterns*) ]]; then
fi fi
[[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] && [[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] &&
service="${_services[-default-]:--default-}" && "$comp" && ret=0 service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
_compskip='' _compskip=''

View file

@ -7,11 +7,17 @@
# `_contexts -math-' to get the completions that would be generated for a # `_contexts -math-' to get the completions that would be generated for a
# mathematical context. # mathematical context.
local i tmp ret=1 service local i tmp ret=1 service or
if [[ $1 = -o ]]; then
or=yes
shift
fi
for i; do for i; do
tmp="$_comps[$i]" tmp="$_comps[$i]"
[[ -z "$tmp" ]] || service="${_services[$i]:-$i}" && "$tmp" && ret=0 [[ -n "$tmp" ]] && service="${_services[$i]:-$i}" && eval "$tmp" && ret=0
[[ -n "$or" && ret -eq 0 ]] && return 0
done done
return ret return ret

View file

@ -16,7 +16,5 @@ fi
shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}" shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
compset -n $base compset -n $base
for name in $shell $shell:t -default-; do
comp="$_comps[$name]" _contexts -o $shell $shell:t -default-
[[ -n "$comp" ]] && "$comp" && return
done

View file

@ -270,6 +270,15 @@ with the tt(#compdef) tag and an argument of the form
`var(cmd)tt(=)var(service)'. This kind of use makes the arguments of `var(cmd)tt(=)var(service)'. This kind of use makes the arguments of
the var(cmd)s be completed as those for the var(services). the var(cmd)s be completed as those for the var(services).
In the first case and the following cases the var(function) may actually
be a string containing any shell code and that string will be executed
via the tt(eval) builtin command. This allows to easily define completions
for commands that need to call one of the completion functions with
arguments. For example to make files ending in `tt(.h)' be completed as
arguments to the command tt(foo), one would use:
example(compdef '_files -g "*.h"' foo)
If the If the
tt(-n) option is given, any existing completion behaviour for particular tt(-n) option is given, any existing completion behaviour for particular
contexts or commands will not be altered. These definitions can be deleted contexts or commands will not be altered. These definitions can be deleted
@ -3518,13 +3527,17 @@ tt(compadd) when generating matches from the style value, or to
the functions for the fields if they are called. the functions for the fields if they are called.
) )
findex(_contexts) findex(_contexts)
item(tt(_contexts) var(names) ...)( item(tt(_contexts) [ tt(-o) ] var(names) ...)(
This function looks up the definitions for the context and command This function looks up the definitions for the context and command
names given as arguments and calls the handler functions for them if names given as arguments and calls the handler functions for them if
there is a definition (given with the tt(compdef) function). For there is a definition (given with the tt(compdef) function). For
example, the function completing inside subscripts might use example, the function completing inside subscripts might use
`tt(_contexts -math-)' to include the completions generated for `tt(_contexts -math-)' to include the completions generated for
mathematical environments. mathematical environments.
If the tt(-o) option is given, tt(_contexts) returns after the first
context for which completions could be generated, without trying the
other contexts.
) )
findex(_describe) findex(_describe)
item(tt(_describe) [ tt(-o) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)( item(tt(_describe) [ tt(-o) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)(