* PATCH: Re: another optional argument problem?
@ 2000-05-08 10:36 Sven Wischnowsky
0 siblings, 0 replies; only message in thread
From: Sven Wischnowsky @ 2000-05-08 10:36 UTC (permalink / raw)
To: zsh-workers
Tanaka Akira wrote:
> Z(5):akr@serein% Src/zsh -f
> serein% bindkey -e; autoload -U compinit; compinit -D; compdef _tst tst
> serein% _tst () { _arguments -s '-o::o:(o)' ':a:(a)' }
> serein% tst -o<TAB>
>
> It should inseart a space, I think.
Yep, because there is no other option.
In another message:
> I found a difference of empty action handling between _arguments and
> _alternative.
>
> Z(5):akr@serein% Src/zsh -f
> serein% bindkey -e; autoload -U compinit; compinit -D
> serein% zstyle ':completion:*:messages' format %d
> serein% compdef _tst1 tst1; _tst1 () { _arguments '-o::o:' ':a:' }
> serein% compdef _tst2 tst2; _tst2 () { _alternative 'option-o-1:o:' 'argument-1:a:' }
>
> serein% tst1 -o <TAB>
> a
>
> serein% tst2 <TAB>
> o
> a
>
> _arguments shows only `a' but _alternative shows both.
That complicated message handling in _arguments. I should have changed
that when I added `compadd -x'.
> They has tags
> `option-o-1' and `argument-1' orderd by defafult tag-order specified
> in _tags. Is this intentional?
Yes. This was caused by _argument_sets. Without this change that would
use the same tag more than once for different completions.
Bye
Sven
Index: Completion/Base/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.11
diff -u -r1.11 _arguments
--- Completion/Base/_arguments 2000/05/08 08:58:37 1.11
+++ Completion/Base/_arguments 2000/05/08 10:35:47
@@ -234,9 +234,8 @@
# An empty action means that we should just display a message.
- [[ -n "$matched" ]] &&
- compadd -n -Q -S '' -s "$SUFFIX" - "$PREFIX"
- mesg="$descr"
+ _message "$descr"
+ mesg=yes
elif [[ "$action" = \(\(*\)\) ]]; then
@@ -361,7 +360,6 @@
[[ -n "$aret" ]] && return 300
- [[ -n "$mesg" ]] && _message "$mesg"
if [[ -n "$noargs" ]]; then
[[ -z "$ismulti" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs"
else
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.13
diff -u -r1.13 computil.c
--- Src/Zle/computil.c 2000/05/05 07:37:17 1.13
+++ Src/Zle/computil.c 2000/05/08 10:35:48
@@ -1072,7 +1072,7 @@
Caarg def, ddef;
Caopt curopt;
int opt, arg, argbeg, optbeg, nargbeg, restbeg, curpos;
- int inopt, inrest, inarg, nth, doff, singles, oopt;
+ int inopt, inrest, inarg, nth, doff, singles, oopt, actopts;
LinkList args;
LinkList *oargs;
};
@@ -1121,7 +1121,7 @@
state.nopts = d->nopts;
state.def = state.ddef = NULL;
state.curopt = NULL;
- state.argbeg = state.optbeg = state.nargbeg = state.restbeg =
+ state.argbeg = state.optbeg = state.nargbeg = state.restbeg = state.actopts =
state.nth = state.inopt = state.inarg = state.opt = state.arg = 1;
state.inrest = state.doff = state.singles = state.doff = state.oopt = 0;
state.curpos = compcurrent;
@@ -1136,7 +1136,7 @@
if (!compwords[1]) {
ca_laststate.opt = ca_laststate.arg = 0;
- return 0;
+ goto end;
}
/* Loop over the words from the line. */
@@ -1349,6 +1349,13 @@
}
}
}
+ end:
+
+ ca_laststate.actopts = 0;
+ for (ptr = d->opts; ptr; ptr = ptr->next)
+ if (ptr->active)
+ ca_laststate.actopts++;
+
return 0;
}
@@ -1574,7 +1581,8 @@
return 1;
}
case 'O':
- if ((ca_laststate.opt || (ca_laststate.doff && ca_laststate.def) ||
+ if (ca_laststate.actopts &&
+ (ca_laststate.opt || (ca_laststate.doff && ca_laststate.def) ||
(ca_laststate.def &&
(ca_laststate.def->type == CAA_OPT ||
(ca_laststate.def->type >= CAA_RARGS &&
@@ -1632,7 +1640,7 @@
}
case 's':
if (ca_laststate.d->single && ca_laststate.singles &&
- ca_laststate.opt) {
+ ca_laststate.actopts > 1 && ca_laststate.opt) {
setsparam(args[1],
ztrdup(ca_laststate.ddef ?
(ca_laststate.ddef->type == CAO_DIRECT ?
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-05-08 10:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-08 10:36 PATCH: Re: another optional argument problem? Sven Wischnowsky
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).