Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: was: oops, a set -x
- X-seq: zsh-workers 8749
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: was: oops, a set -x
- Date: Tue, 23 Nov 1999 15:12:12 +0100 (MET)
- In-reply-to: Tanaka Akira's message of 13 Nov 1999 01:08:47 +0900
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Tanaka Akira wrote:
> In article <199911121503.QAA30053@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx> writes:
>
> > Tanaka: have you mentioned that at the time you wrote it and I missed
> > it? I tried and since `_telnet' doesn't support options for my
> > `telnet' at all, I couldn't find out what goes wrong with these
> > options. Could you explain that to me so that we can fix it and
> > simplify `_telnet'?
>
> I wrote _telnet with the telnet source of FreeBSD.
> http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/telnet/main.c?rev=1.9
>
> It may have short option "-n" and long options "-noasynch",
> "-noasynchtty" and "-noasynchnet" under some circumstances. These
> long options are implemented by special case of short option "-n".
>
> When completion is tryed just after "-n", zsh cannot decide that it is
> the short option or not. So, _telnet should complete option arguments
> for "-n" and long options as:
>
> % telnet -<TAB>
> -n -noasynch -noasynchtty -noasynchnet and other options
>
> % telnet -n<TAB>
> -noasynch -noasynchtty -noasynchnet and filenames
>
> % telnet -n <TAB>
> filenames
>
> % telnet -no<TAB>
> -noasynch -noasynchtty -noasynchnet and filenames start with "o".
This patch should do the job. One `side-effect' is that _arguments in
single-letter mode now prefers to take strings from the line as long
options if possible. I.e. if possible options are `-b', `-a', `-r',
and `-bar' and you do `foo -bar -<TAB>', it will take the `-bar' as
the the option `-bar' and offer you only the other ones. But I think
this is actually a good change.
I've tested the whole thing with:
_arguments -s \
'-n+:xx:(foo bar)' -k -l \
'-lnoasync' -lnofrob -noasync
...to make sure that in this case even `-ln<TAB>' does the right thing
(take it as the options `-l' and `-n' or the start of `-lno*').
However, I have *not* change _telnet because, as I said, I don't have
a version with these options. Tanaka, could you...? If I'm not
completely mistaken it should just make it much simpler.
Bye
Sven
P.S.: It also required some saving/restoring of $PREFIX and $IPREFIX
in _arguments.
diff -u oldsrc/Zle/computil.c Src/Zle/computil.c
--- oldsrc/Zle/computil.c Tue Nov 23 12:49:14 1999
+++ Src/Zle/computil.c Tue Nov 23 15:00:41 1999
@@ -941,13 +941,17 @@
{
Caopt p;
- if (full) {
- /* The full string has to be an option. */
+ /* The full string may be an option. */
- for (p = d->opts; p; p = p->next)
- if (p->active && !strcmp(p->name, line))
- return p;
- } else {
+ for (p = d->opts; p; p = p->next)
+ if (p->active && !strcmp(p->name, line)) {
+ if (end)
+ *end = line + strlen(line);
+
+ return p;
+ }
+
+ if (!full) {
/* The string from the line probably only begins with an option. */
for (p = d->opts; p; p = p->next)
if (p->active && ((!p->args || p->type == CAO_NEXT) ?
@@ -1160,7 +1164,7 @@
} LASTALLOC;
ca_inactive(d, state.curopt->xor);
- /* Collect the argument strings. MAybe. */
+ /* Collect the argument strings. Maybe. */
if (state.def &&
(state.curopt->type == CAO_DIRECT ||
@@ -1431,7 +1435,7 @@
return 1;
}
case 'O':
- if (ca_laststate.opt) {
+ if (ca_laststate.opt || (ca_laststate.doff && ca_laststate.def)) {
LinkList next = newlinklist();
LinkList direct = newlinklist();
LinkList odirect = newlinklist();
@@ -1484,7 +1488,8 @@
return 1;
}
case 's':
- if (ca_laststate.d->single && ca_laststate.singles) {
+ if (ca_laststate.d->single && ca_laststate.singles &&
+ ca_laststate.opt) {
setsparam(args[1],
ztrdup(ca_laststate.ddef ?
(ca_laststate.ddef->type == CAO_DIRECT ?
diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments Tue Nov 23 12:50:00 1999
+++ Completion/Base/_arguments Tue Nov 23 15:00:20 1999
@@ -165,8 +165,9 @@
if comparguments -i "$autod" "$@"; then
local nm="$compstate[nmatches]" action noargs aret expl local
- local next direct odirect equal single match matched ws tmp1 tmp2
+ local next direct odirect equal single match matched ws tmp1 tmp2 tmp3
local opts subc prefix suffix
+ local origpre="$PREFIX" origipre="$IPREFIX"
if comparguments -D descr action; then
comparguments -C subc
@@ -254,11 +255,17 @@
fi
fi
fi
+
if [[ -z "$matched" ]] && _requested options &&
{ ! _style options prefix-needed ||
- [[ "$PREFIX" = [-+]* ]] } ; then
- comparguments -M match
+ [[ "$origpre" = [-+]* ]] } ; then
+ local prevpre="$PREFIX" previpre="$IPREFIX"
+
+ PREFIX="$origpre"
+ IPREFIX="$origipre"
+ comparguments -M match
+
if comparguments -s single; then
_description expl option
@@ -271,11 +278,13 @@
compadd "$expl[@]" -QqS= - "${PREFIX}${SUFFIX}"
else
tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" )
+ tmp3=( "${(M@)tmp1:#[-+]?[^:]*}" )
tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" )
_describe -o option \
- tmp1 tmp2 -Q -S ''
+ tmp1 tmp2 -Q -S '' -- \
+ tmp3 -Q
fi
single=yes
else
@@ -285,10 +294,15 @@
direct -QS '' -M "$match" -- \
equal -QqS= -M "$match"
fi
+ PREFIX="$prevpre"
+ IPREFIX="$previpre"
fi
done
if [[ -n "$opts" && -z "$aret$matched" &&
nm -eq compstate[nmatches] ]]; then
+
+ PREFIX="$origpre"
+ IPREFIX="$origipre"
prefix="${PREFIX#*\=}"
suffix="$SUFFIX"
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author