Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- X-seq: zsh-workers 16472
- From: Sven Wischnowsky <wischnow@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
- Date: Mon, 21 Jan 2002 17:09:30 +0100
- In-reply-to: <20020107160652.11027.qmail@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <15417.46354.791905.730459@xxxxxxxxxxxxxxxxxx> <20020107160652.11027.qmail@xxxxxxxxxxxxxxxxxxxxxx>
Oliver Kiddle wrote:
> --- Sven Wischnowsky <wischnow@xxxxxxxxx> wrote: >
>
> > And here is a patch for this. Not very nice, because we use $_comps
> > in several places and I've just added `eval's there. Probably should
> > be put into a separate function, but somehow it looks to small and
> > simple for that.
>
> It could be useful as a utility function anyway though. That it would
> be used in _su convinces me. Including the $service setting stuff would
> make it slightly less small. Perhaps it could be merged with _contexts
> which is similar anyway.
>
> > This, too, I'm not going to commit until I get replies.
>
> It looks good to me and seems to work well. Using eval instead of $=tmp
> is not something I'd thought about. I suppose it might be useful to get
> at one of the special variables like $words or $QIPREFIX.
Here is a better patch and I'm going to commit it this time.
I've left the calls to `eval' in _complete and _normal, these
functions are just too specialised to put that code into a separate
function (and they are part of the core system anyway). For _su I've
given _contexts an option (-o) that makes the contexts be or'ed, i.e.
_contexts returns as soon as completions could be generated for one of
the contexts.
Bye
Sven
Index: Completion/Base/Completer/_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_complete,v
retrieving revision 1.1
diff -u -r1.1 _complete
--- Completion/Base/Completer/_complete 2001/04/02 11:06:01 1.1
+++ Completion/Base/Completer/_complete 2002/01/21 16:03:55
@@ -85,7 +85,7 @@
ccarray[3]="$compcontext"
comp="$_comps[$compcontext]"
- [[ -z "$comp" ]] || "$comp"
+ [[ -n "$comp" ]] && eval "$comp"
fi
return
@@ -94,10 +94,10 @@
# An entry for `-first-' is the replacement for `compctl -T'
comp="$_comps[-first-]"
-if [[ ! -z "$comp" ]]; then
+if [[ -n "$comp" ]]; then
service="${_services[-first-]:--first-}"
ccarray[3]=-first-
- "$comp" && ret=0
+ eval "$comp" && ret=0
if [[ "$_compskip" = all ]]; then
_compskip=
return ret
@@ -135,8 +135,8 @@
fi
comp="$_comps[-default-]"
fi
- [[ -z "$comp" ]] ||
- service="${_services[-default-]:--default-}" && "$comp" && ret=0
+ [[ -n "$comp" ]] &&
+ service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
fi
_compskip=
Index: Completion/Base/Core/_normal
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_normal,v
retrieving revision 1.1
diff -u -r1.1 _normal
--- Completion/Base/Core/_normal 2001/04/02 11:04:04 1.1
+++ Completion/Base/Core/_normal 2002/01/21 16:03:55
@@ -19,7 +19,7 @@
curcontext="${curcontext%:*:*}:-command-:"
comp="$_comps[-command-]"
- [[ -z "$comp" ]] || "$comp" && ret=0
+ [[ -n "$comp" ]] && eval "$comp" && ret=0
return ret
else
@@ -86,7 +86,7 @@
if [[ -n "$comp" ]]; then
_compskip=patterns
- "$comp" && ret=0
+ eval "$comp" && ret=0
[[ "$_compskip" = (all|*patterns*) ]] && return ret
elif [[ "$_compskip" != *default* ]]; then
name=-default-
@@ -121,7 +121,7 @@
fi
[[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] &&
- service="${_services[-default-]:--default-}" && "$comp" && ret=0
+ service="${_services[-default-]:--default-}" && eval "$comp" && ret=0
_compskip=''
Index: Completion/Base/Utility/_contexts
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_contexts,v
retrieving revision 1.1
diff -u -r1.1 _contexts
--- Completion/Base/Utility/_contexts 2001/04/02 11:10:27 1.1
+++ Completion/Base/Utility/_contexts 2002/01/21 16:03:55
@@ -7,11 +7,17 @@
# `_contexts -math-' to get the completions that would be generated for a
# 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
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
return ret
Index: Completion/Unix/Command/_su
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_su,v
retrieving revision 1.1
diff -u -r1.1 _su
--- Completion/Unix/Command/_su 2001/04/02 12:03:16 1.1
+++ Completion/Unix/Command/_su 2002/01/21 16:03:55
@@ -16,7 +16,5 @@
shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
compset -n $base
-for name in $shell $shell:t -default-; do
- comp="$_comps[$name]"
- [[ -n "$comp" ]] && "$comp" && return
-done
+
+_contexts -o $shell $shell:t -default-
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.139
diff -u -r1.139 compsys.yo
--- Doc/Zsh/compsys.yo 2002/01/10 11:00:05 1.139
+++ Doc/Zsh/compsys.yo 2002/01/21 16:03:56
@@ -270,6 +270,15 @@
`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).
+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
tt(-n) option is given, any existing completion behaviour for particular
contexts or commands will not be altered. These definitions can be deleted
@@ -3518,13 +3527,17 @@
the functions for the fields if they are called.
)
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
names given as arguments and calls the handler functions for them if
there is a definition (given with the tt(compdef) function). For
example, the function completing inside subscripts might use
`tt(_contexts -math-)' to include the completions generated for
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)
item(tt(_describe) [ tt(-o) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)(
--
Sven Wischnowsky wischnow@xxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author