Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: complete (real C) tags
- X-seq: zsh-workers 11459
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: Re: complete (real C) tags
- Date: Thu, 18 May 2000 12:46:15 +0200 (MET DST)
- In-reply-to: Peter Stephenson's message of Wed, 17 May 2000 15:54:14 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Peter Stephenson wrote:
> I don't think I ever posted this; it allows the new completion system to
> complete tags from a TAGS or tags file (i.e. the tags used by Emacs and vi,
> nothing to do with completion tags). I have it bound to ^Xt.
>
> I was going to send it to zshu, until I realised it didn't use style tags,
> and tried to make it by sticking the _wanted stuff in front, which failed,
> so I took it off again. Only one man will know why...
This showed a problem with _wanted and friends: they need some setup
done by _main_complete. But one way of fixing this gives a nice
enhancement to _main_complete, as in the patch below. If it is called
with arguments and the first one is a `-', then the second one is
taken as a name to stuff into the completer field of the context and
the other arguments give a command with its arguments to call to
generate the matches. So, this would be the patch to _complete_tag
(not committed because there is no _complete_tag yet):
--- _complete_tag.old Thu May 18 11:54:39 2000
+++ _complete_tag Thu May 18 12:26:26 2000
@@ -14,6 +14,14 @@
local c_Tagsfile=${TAGSFILE:-TAGS} c_tagsfile=${tagsfile:-tags} expl
# Max no. of directories to scan up through
integer c_maxdir=10
+# Context.
+local curcontext="$curcontext"
+
+if [[ -z "$curcontext" ]]; then
+ curcontext="complete-tag:::"
+else
+ curcontext="complete-tag:${curcontext#*:}"
+fi
local c_path=
integer c_idir
@@ -30,16 +38,16 @@
# after quarter of an hour of trying, except for
# rm -f =sed; ln -s /usr/local/bin/perl /usr/bin/sed
# but that's widely regarded as cheating.
- # _wanted etags expl 'emacs tags'
- compadd - \
- $(perl -ne '/([a-zA-Z_0-9]+)[ \t:;,\(]*\x7f/ &&
- print "$1\n"' $c_path$c_Tagsfile)
+ _main_complete - '' _wanted etags expl 'emacs tags' \
+ compadd - \
+ $(perl -ne '/([a-zA-Z_0-9]+)[ \t:;,\(]*\x7f/ &&
+ print "$1\n"' $c_path$c_Tagsfile)
elif [[ -f $c_tagspath ]]; then
# tags doesn't have as much in, but the tag is easy to find.
# we can use awk here.
- # _wanted vtags expl 'vi tags'
- compadd - \
- $(awk '{ print $1 }' $c_path$c_Tagsfile)
+ _main_complete - '' _wanted vtags expl 'vi tags' \
+ compadd - \
+ $(awk '{ print $1 }' $c_path$c_Tagsfile)
else
return 1
fi
And here is the patch for the change to _main_complete...
Bye
Sven
Index: Completion/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v
retrieving revision 1.20
diff -u -r1.20 _main_complete
--- Completion/Core/_main_complete 2000/05/17 06:50:03 1.20
+++ Completion/Core/_main_complete 2000/05/18 10:46:21
@@ -20,7 +20,7 @@
unsetopt markdirs globsubst shwordsplit nounset ksharrays
exec </dev/null # ZLE closes stdin, which can cause errors
-local func funcs ret=1 tmp _compskip format nm \
+local func funcs ret=1 tmp _compskip format nm call \
_completers _completer _completer_num curtag _comp_force_list \
_matchers _matcher _matcher_num _comp_tags _comp_mesg \
context state line opt_args val_args curcontext="$curcontext" \
@@ -84,7 +84,16 @@
# Get the names of the completers to use in the positional parameters.
if (( $# )); then
- _completers=( "$@" )
+ if [[ "$1" = - ]]; then
+ if [[ $# -lt 3 ]]; then
+ _completers=()
+ else
+ _completers=( "$2" )
+ call=yes
+ fi
+ else
+ _completers=( "$@" )
+ fi
else
zstyle -a ":completion:${curcontext}:" completer _completers ||
_completers=( _complete _ignored )
@@ -104,7 +113,9 @@
for tmp in "$_completers[@]"; do
- if [[ "$tmp" = *:-* ]]; then
+ if [[ -n "$call" ]]; then
+ _completer="${tmp}"
+ elif [[ "$tmp" = *:-* ]]; then
_completer="${${tmp%:*}[2,-1]//_/-}${tmp#*:}"
tmp="${tmp%:*}"
elif [[ $tmp = *:* ]]; then
@@ -120,7 +131,12 @@
_matcher_num=1
for _matcher in "$_matchers[@]"; do
- if "$tmp"; then
+ if [[ -n "$call" ]]; then
+ if "${(@)argv[3,-1]}"; then
+ ret=0
+ break 2
+ fi
+ elif "$tmp"; then
ret=0
break 2
fi
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.50
diff -u -r1.50 compsys.yo
--- Doc/Zsh/compsys.yo 2000/05/18 09:22:31 1.50
+++ Doc/Zsh/compsys.yo 2000/05/18 10:46:22
@@ -2003,6 +2003,12 @@
value is zero, no other completers are tried and the tt(_main_complete)
function returns.
+If the first argument to tt(_main_complete) is a single hyphen, the
+arguments will not be taken as names of completers. Instead, the
+second argument gives a name to use in the var(completer) field of the
+context and the other arguments give a command anme and arguments to
+call to generate the matches.
+
The following completer functions are contained in the distribution (users
may write their own):
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author