zsh-workers
 help / color / mirror / code / Atom feed
* Problem with _arguments and invalid options
@ 1999-09-10 13:23 Andrej Borsenkow
  1999-09-10 16:19 ` Problem with _arguments and _normal as action if nolistambiguous is set Andrej Borsenkow
  0 siblings, 1 reply; 4+ messages in thread
From: Andrej Borsenkow @ 1999-09-10 13:23 UTC (permalink / raw)
  To: ZSH workers mailing list

Currently, invalid (not listed in description) options are not handled very
nicely. Here is half-hearted example of sudo completion:

_arguments \
	'-V[show version]' \
	'-l[list commands]' \
	'-h[show help]' \
	'-v[validate timestamp file]' \
	'-k[remove timestamp file]' \
	'-b[run command in background]' \
	'-r:Kerberos realm:' \
	'-p:prompt:' \
	'-u:user name:_users' \
	'-s[run SHELL]' \
	'-H[set HOME environment variable]' \
	'*::complete command and/or arguments:_normal'

And now

bor@itsrm2:~/.zsh.d/completion%> sudo -z TAB
bor@itsrm2:~/.zsh.d/completion%> sudo -z _normal: bad option: -z [33]
_
--- file
_sudo     _umount

What's worse - if a command does not list `-s', but you *do* give `-s' - it
seems to be propagated downward and interpreted by _arguments itself (or some
other function, dunno). Just remove definition for -s from above and try:

bor@itsrm2:~/.zsh.d/completion%> sudo -u nTAB
bor@itsrm2:~/.zsh.d/completion%> sudo -u n
--- user
nerv     nobody   nuucp

but

bor@itsrm2:~/.zsh.d/completion%> sudo -s -u nTAB
B-e-e-p

and

bor@itsrm2:~/.zsh.d/completion%> sudo -s -u TAB
bor@itsrm2:~/.zsh.d/completion%> sudo -s -u _
--- file
_sudo     _umount


/andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Problem with _arguments and _normal as action if nolistambiguous is set.
  1999-09-10 13:23 Problem with _arguments and invalid options Andrej Borsenkow
@ 1999-09-10 16:19 ` Andrej Borsenkow
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 1999-09-10 16:19 UTC (permalink / raw)
  To: ZSH workers mailing list

With the sudo completion as below, I get very funny results. It does not happen
if I use _files as action instead of _normal. The arguments itself are completed
correctly (that is, command name and parameters), but sudo -TAB is at least
strange.

Again, it is 3.1.6-pws-3 with patches up to 7750

bor@itsrm2:~/.zsh.d/completion%> zsh -f
itsrm2% autoload compinit
itsrm2% fpath=($fpath ~/.zsh.d/completion)
itsrm2% compinit -D
itsrm2% setopt nolistambiguous
itsrm2% compconf describe_options=yes
itsrm2% sudo -TAB
itsrm2% sudo <=cursor here
-
-H -- set HOME environment variable
-V -- show version
-b -- run command in background
-h -- show help
-k -- remove timestamp file
-l -- list commands
-s -- run SHELL
-v -- validate timestamp file
-p  -r  -u

TAB once more

itsrm2% sudo !<=cursor
-
-H -- set HOME environment variable
-V -- show version
-b -- run command in background
-h -- show help
-k -- remove timestamp file
-l -- list commands
-s -- run SHELL
-v -- validate timestamp file
-p  -r  -u

TAB once more

itsrm2% sudo !!<=cursor
-
-H -- set HOME environment variable
-V -- show version
-b -- run command in background
-h -- show help
-k -- remove timestamp file
-l -- list commands
-s -- run SHELL
-v -- validate timestamp file
-p  -r  -u


Here is half-hearted example of sudo completion:
>
> _arguments \
> 	'-V[show version]' \
> 	'-l[list commands]' \
> 	'-h[show help]' \
> 	'-v[validate timestamp file]' \
> 	'-k[remove timestamp file]' \
> 	'-b[run command in background]' \
> 	'-r:Kerberos realm:' \
> 	'-p:prompt:' \
> 	'-u:user name:_users' \
> 	'-s[run SHELL]' \
> 	'-H[set HOME environment variable]' \
> 	'*::complete command and/or arguments:_normal'
>


/andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with _arguments and _normal as action if nolistambiguous is set.
@ 1999-09-14  9:50 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1999-09-14  9:50 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Andrej Borsenkow wrote:
> 
> > itsrm2% sudo -TAB
> > itsrm2% sudo <=cursor here
> 
> This is a really ugly bug. It comes from the fact that the options are 
> added with a `r:|-=*' match spec and commands are not. The completion
> code currently can't merge the unambiguous string information if the
> equal substrings are in an anchor for some matches and in a normal
> string-part for other matches.

This should do it by turning sequences of cline structs for anchrs
(and their prefixes) into a prefix and then trying to join the two
lists again.

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Tue Sep 14 09:08:46 1999
+++ Src/Zle/zle_tricky.c	Tue Sep 14 11:46:44 1999
@@ -1946,7 +1946,7 @@
 {
     Cline r;
 
-    /* Preverably take it from the buffer list (freecl), if there
+    /* Prefer to take it from the buffer list (freecl), if there
      * is none, allocate a new one. */
 
     if ((r = freecl))
@@ -1981,6 +1981,28 @@
     }
 }
 
+/* Copy a cline list. */
+
+static Cline
+cp_cline(Cline l)
+{
+    Cline r = NULL, *p = &r, t;
+
+    while (l) {
+	if ((t = freecl))
+	    freecl = t->next;
+	else
+	    t = (Cline) zhalloc(sizeof(*t));
+	memcpy(t, l, sizeof(*t));
+	*p = t;
+	p = &(t->next);
+	l = l->next;
+    }
+    *p = NULL;
+
+    return r;
+}
+
 /* This reverts the order of the elements of the given cline list and
  * returns a pointer to the new head. */
 
@@ -3365,6 +3387,50 @@
     n->suffix = NULL;
 }
 
+/* This turns the sequence of anchor cline structs from b to e into a
+ * prefix sequence, puts it before the prefix of e and then tries to
+ * join that with the prefix of a.
+ * This is needed if some matches had a anchor match spec and others
+ * didn't. */
+
+static void
+sub_join(Cline a, Cline b, Cline e, int anew)
+{
+    if (!e->suffix && a->prefix) {
+	Cline op = e->prefix, n = NULL, *p = &n, t, ca;
+
+	for (; b != e; b = b->next) {
+	    if ((*p = t = b->prefix)) {
+		while (t->next)
+		    t = t->next;
+		p = &(t->next);
+	    }
+	    b->suffix = b->prefix = NULL;
+	    b->flags &= ~CLF_SUF;
+	    *p = b;
+	    p = &(b->next);
+	}
+	*p = e->prefix;
+	ca = a->prefix;
+
+	while (n != op) {
+	    e->prefix = cp_cline(n);
+	    a->prefix = cp_cline(ca);
+
+	    if (anew) {
+		join_psfx(e, a, NULL, NULL, 0);
+		if (e->prefix)
+		    break;
+	    } else {
+		join_psfx(e, a, NULL, NULL, 0);
+		if (a->prefix)
+		    break;
+	    }
+	    n = n->next;
+	}
+    }
+}
+
 /* This simplifies the cline list given as the first argument so that
  * it also matches the second list. */
 
@@ -3388,11 +3454,7 @@
 
 		for (t = o; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
 		if (tn && cmp_anchors(tn, n, 0)) {
-		    Cline tmp;
-
-		    tmp = o->prefix;
-		    o->prefix = tn->prefix;
-		    tn->prefix = tmp;
+		    sub_join(n, o, tn, 1);
 
 		    if (po)
 			po->next = tn;
@@ -3410,11 +3472,7 @@
 
 		for (t = n; (tn = t->next) && (tn->flags & CLF_NEW); t = tn);
 		if (tn && cmp_anchors(o, tn, 0)) {
-		    Cline tmp;
-
-		    tmp = n->prefix;
-		    n->prefix = tn->prefix;
-		    tn->prefix = tmp;
+		    sub_join(o, n, tn, 0);
 
 		    n = tn;
 		    o->flags |= CLF_MISS;
@@ -3433,10 +3491,8 @@
 			 (o->flags  & (CLF_SUF | CLF_MID));
 		     t = tn);
 		if (tn && cmp_anchors(o, tn, 1)) {
-		    Cline t;
+		    sub_join(o, n, tn, 0);
 
-		    t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
-		    t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
 		    n = tn;
 		    continue;
 		}
@@ -3446,6 +3502,7 @@
 			 (n->flags  & (CLF_SUF | CLF_MID));
 		     t = tn);
 		if (tn && cmp_anchors(tn, n, 1)) {
+		    sub_join(n, o, tn, 1);
 		    if (po)
 			po->next = tn;
 		    else
@@ -3474,8 +3531,8 @@
 		for (t = n; (tn = t->next) && !cmp_anchors(o, tn, 1); t = tn);
 
 		if (tn) {
-		    t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
-		    t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
+		    sub_join(o, n, tn, 0);
+
 		    n = tn;
 		    o->flags |= CLF_MISS;
 		    continue;
@@ -3484,8 +3541,8 @@
 			 t = tn);
 
 		    if (tn) {
-			t = tn->prefix; tn->prefix = o->prefix; o->prefix = t;
-			t = tn->suffix; tn->suffix = o->suffix; o->suffix = t;
+			sub_join(n, o, tn, 1);
+
 			if (po)
 			    po->next = tn;
 			else

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with _arguments and _normal as action if nolistambiguous is set.
@ 1999-09-13 13:30 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1999-09-13 13:30 UTC (permalink / raw)
  To: zsh-workers


Andrej Borsenkow wrote:

> itsrm2% sudo -TAB
> itsrm2% sudo <=cursor here

This is a really ugly bug. It comes from the fact that the options are 
added with a `r:|-=*' match spec and commands are not. The completion
code currently can't merge the unambiguous string information if the
equal substrings are in an anchor for some matches and in a normal
string-part for other matches.

And the more I think about ways to solve this the more complicated it
gets. So I'll need some more time.

> TAB once more
> 
> itsrm2% sudo !<=cursor

Here the completion code starts completing the matches for command
position. And they include the `!' (the `not' operaator/precommand
specifier).

> itsrm2% sudo !!<=cursor

I don't get this doubled `!'. For me it just continues inserting
command names and such things.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-09-14  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-10 13:23 Problem with _arguments and invalid options Andrej Borsenkow
1999-09-10 16:19 ` Problem with _arguments and _normal as action if nolistambiguous is set Andrej Borsenkow
1999-09-13 13:30 Sven Wischnowsky
1999-09-14  9:50 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).