Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: _argument_sets problem



Tanaka Akira wrote:

> Z(4):akr@serein% Src/zsh -f
> serein% bindkey -e; autoload -U compinit; compinit -D; compdef _tst tst
> serein% zstyle ':completion:*' group-name ''
> serein% zstyle ':completion:*:messages' format %d
> serein% zstyle ':completion:*:descriptions' format %d
> serein% _tst () {
> function>      _argument_sets \
> function>          -a -b \
> function>        - '(compress)' {-c,--compress}'[compress]' \
> function>        - '(uncompress)' \
> function>          {-d,--decompress}'[decompress]'
> function> }
> serein% tst <TAB>
> no arguments
> 
> Hm.

I was about to say that I knew about this and that this is a problem
because _argument_sets has to cal _arguments for each set, so that
_arguments can't know that it can add the options because there are no 
argument-matches, but then I realised that with the last changes, we
can make this possible without too much ado. Hence: thanks for the
reminder.


So, this makes _argument_sets add the options as matches in cases
where _arguments would normally do it. There is also a small fixlet
for the C-code.

Bye
 Sven

Index: Completion/Base/_argument_sets
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_argument_sets,v
retrieving revision 1.3
diff -u -r1.3 _argument_sets
--- Completion/Base/_argument_sets	2000/05/11 08:54:47	1.3
+++ Completion/Base/_argument_sets	2000/05/11 11:24:31
@@ -59,6 +59,10 @@
 done
 
 [[ -n "$_ms_opt" ]] &&
+   { ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
+     [[ "$PREFIX" = [-+]* ||
+     ( -z "$has_args" && ret -ne 300 && nm -eq compstate[nmatches] ) ]] } &&
+  has_args=yes &&
   _describe -o option \
             _ms_soptmid _ms_soptmidadd -Q -S '' -- \
 	    _ms_soptend -Q -- \
Index: Completion/Base/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.15
diff -u -r1.15 _arguments
--- Completion/Base/_arguments	2000/05/11 08:54:47	1.15
+++ Completion/Base/_arguments	2000/05/11 11:24:33
@@ -287,9 +287,10 @@
       done
 
       if [[ -z "$matched$hasopts" ]] && _requested options &&
-          { ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
+          { [[ -n "$ismulti" ]] ||
+            ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
             [[ "$origpre" = [-+]* ||
-            ( -z "$aret$mesg" && nm -eq compstate[nmatches] ) ]] } ; then
+               ( -z "$aret$mesg" && nm -eq compstate[nmatches] ) ]] } ; then
 	local prevpre="$PREFIX" previpre="$IPREFIX"
 
 	hasopts=yes
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.19
diff -u -r1.19 computil.c
--- Src/Zle/computil.c	2000/05/11 08:54:47	1.19
+++ Src/Zle/computil.c	2000/05/11 11:24:38
@@ -1339,7 +1339,7 @@
 		state.nargbeg = cur - 1;
 		state.argend = argend;
 	    }
-	    if (!d->args && !d->rest && *line != '-' && *line != '+')
+	    if (!d->args && !d->rest && *line && *line != '-' && *line != '+')
 		return 1;
 	    if ((adef = state.def = ca_get_arg(d, state.nth)) &&
 		(state.def->type == CAA_RREST ||

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author