From: Sven Wischnowsky <wischnow@berkom.de>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: _file_systems & Re: zstyle for _arguments feature request
Date: Mon, 21 Jan 2002 17:09:30 +0100 [thread overview]
Message-ID: <15436.15674.724403.240491@wischnow.berkom.de> (raw)
In-Reply-To: <20020107160652.11027.qmail@web9303.mail.yahoo.com>
Oliver Kiddle wrote:
> --- Sven Wischnowsky <wischnow@berkom.de> 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@berkom.de
next prev parent reply other threads:[~2002-01-21 16:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-11 15:24 Oliver Kiddle
2002-01-07 14:45 ` Sven Wischnowsky
2002-01-07 14:47 ` Sven Wischnowsky
2002-01-07 16:06 ` Oliver Kiddle
2002-01-21 16:09 ` Sven Wischnowsky [this message]
2001-12-11 15:38 Wischnowsky, Sven
2002-01-08 6:26 Felix Rosencrantz
2002-01-08 8:26 ` Sven Wischnowsky
2002-01-09 7:19 Felix Rosencrantz
2002-01-10 13:46 ` Sven Wischnowsky
2002-01-14 12:34 ` Oliver Kiddle
2002-01-18 8:47 ` Sven Wischnowsky
2002-01-22 2:35 Felix Rosencrantz
2002-01-28 16:37 ` Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15436.15674.724403.240491@wischnow.berkom.de \
--to=wischnow@berkom.de \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).