zsh-workers
 help / color / mirror / code / Atom feed
* Re:  PATCH: zsh-3.1.5-pws-6: bash-style completion
@ 1999-02-04 14:40 Dag-Erling Smorgrav
  0 siblings, 0 replies; 9+ messages in thread
From: Dag-Erling Smorgrav @ 1999-02-04 14:40 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
> Peter Stephenson wrote:
> > We seem to have this discussion every week.  It's not like bash,
> > because bash only shows the list on the *second* tab, and zsh can't
> > currently do that.
> I *know* that the thing I suggested shows behavior unlike bash. I was
> referring to the patch he sent which (as far as I can see, without
> testing it) should behave like LISTAMBIGUOUS plus AUTOLIST.

The patch I sent behaves like bash, i.e. shows the list on the second
tab. My first attempt didn't (I ran docomplete(COMP_COMPLETE) once,
*then* docomplete(COMP_LIST_COMPLETE) if lastambig was non-zero,
instead of running docomplete(COMP_COMPLETE) only if lastambig was
zero) but the one I sent does.

I haven't tried LIST_AMBIGUOUS + AUTO_LIST, so I can't comment on
whether or not my patch behaves like that.

DES (who ended up subscribing to -workers anyway)
-- 
Dag-Erling Smorgrav - des@flood.ping.uio.no


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: PATCH: zsh-3.1.5-pws-6: bash-style completion
@ 1999-02-05  9:51 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 1999-02-05  9:51 UTC (permalink / raw)
  To: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2962 bytes --]


Here is the comment on completion-matching and cursor-positioning.

Peter Stephenson wrote:

> % zsh -f
> % compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
> % echo z<TAB>
>        ^cursor is now over the z.

In a certain sense, this is correct. The matching code has to deal
with to possible differences between what was on the line and the
matches: character differencs and substrings that appear in the
match(es), but not on the line. The rule used is to position the
cursor preferably at a position where characters are missing and, if
there are no such places, to position the cursor on the first
character difference so that the user can type ^D, insert the wanted
character and type tab. My patch that `fixed' this places the cursor
after the first differing character (so that backspace-char-tab can be 
used, which is easy enough to type, too).

Now, some people may already have noticed that the code that inserts
this unambiguous string into the command line isn't very powerful. To
be more exact: it has problems with those parts of the matches that
differ from match to match and that don't have a corresponding part
typed by the user. Examples:

- With -M 'm:{a-z}={A-Z}' completing an empty prefix with the two 
  possible matches `Foobar' and `foobaz' the code should insert
  `fooba' with the cursor after it. With possible matches `Foobar' and
  `foobar' it should insert `foobar' with the cursor after
  (previously: on) the `f'. This could be done by checking if a match
  matches all the other matches. Doing this fast enough is already not 
  that easy.
- This also wouldn't help much. Consider the same match specification
  with the matches `Foobar' and `fooBar'. Here the code would have to
  check parts of matches against each other. Doing so with no hint
  where these parts are (i.e. chunks of characters that should be tested
  as groups), is already quite complicated.
- This gets worse if there are match specifications with different
  lengths for the line/word-patterns. With -M 'm:{a-z}={A-Z} m:ß=SS'
  and the matches `MASSE' and `Maße' we would want `Maße' to be inserted.
- All these examples were `simple' in the sense that the parts of the
  string to insert appeared in the matches, but this need not be. With
  -M 'm:{a-z}={A-Z} m:{aou}e={äöü}' and the matches `MUEHE' and `Mühe' 
  we'd like to have `Muehe' inserted where the `ue' was derived only
  from looking at the matching specification. (And in a German
  language environment a matching specification like the one given may 
  really be used - for `ä' you need to type four keys.)

Of course all this can be intermixed with partial word completion etc.

So, I'll have to think about all this some more to find out what can
be done without too much effort and without being too slow. I'll be
gratefull for every opinion, suggestion, and comment I'll get about
all this.

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: PATCH: zsh-3.1.5-pws-6: bash-style completion
@ 1999-02-05  8:28 Sven Wischnowsky
  1999-02-05  9:17 ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Wischnowsky @ 1999-02-05  8:28 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> Sven Wischnowsky wrote:
> > > I've also been having strange effects when combining all this with:
> > >   compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
> > 
> > Hm, I haven't found any unusual behavior here, so I guess, I need an
> > example.
> 
> The following alone works for me, in the Src directory of the
> distribution where z<TAB> is ambiguous.
> 
> % zsh -f
> % compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
> % echo z<TAB>
>        ^cursor is now over the z.
> 
> Now delete the line with ^U, enter `compctl -M', and try the same
> example again, and the shell dies.

The patch below fixes both of these. I'll write an extra comment about 
the positioning of the cursor.

> > I have only a bash-2.01.1 here but that version shows the behavior to
> > list the matches only on the third TAB: 1) insert unambiguous prefix,
> > 2) do nothing, 3) show list. If the unambiguous prefix was completely
> > typed (not automatically inserted), it first does nothing and shows
> > the list on the second TAB. So I'd vote for removing the test, see the 
> > patch below which also fixes a typo in your patch. Otherwise using
> > BASHAUTOLIST will be the same as LISTAMBIGUOUS+AUTOLIST if the
> > unambiguous prefix had to be automatically inserted.
> 
> That's fine by me; you can unset LISTAMBIGUOUS to get the other
> behaviour.  The patch changes the documentation.
> 
> However, I'm having problems with LISTAMBIGUOUS when RECEXACT is set,
> because `am' then gets set a few lines above that, apparently even if
> there isn't an exact completion, and the chunk in question is skipped.
> Any ideas?

Yes, there was a problem with listambiguous showing the list too
early. This was caused by a wrong calculation in ainfo->prerest. I've
changed that to collect the minimum match length and compare it to
what is inserted.

Another problem I can see is the combination of menucomplete and
bashautolist. Here the list is never shown since we never get to the
second tab. Maybe we should just document this.

Bye
 Sven

--- oos/Zle/zle_tricky.c	Fri Feb  5 08:49:33 1999
+++ Src/Zle/zle_tricky.c	Fri Feb  5 09:26:42 1999
@@ -223,7 +223,7 @@
 
 struct aminfo {
     int cpl, csl, icpl, icsl;	/* common prefix/suffix lengths           */
-    int prerest;		/* minimum prefix rest                    */
+    int minlen;			/* minimum match length                   */
     int suflen;			/* minimum suffix length                  */
     Cmatch firstm;		/* the first match                        */
     char *pprefix;		/* common part of the -P prefixes         */
@@ -1824,9 +1824,17 @@
     pl += brpl;
 
     i = cs - wb;
+    if (pl >= 0 && i >= pl && brbeg && *brbeg) {
+	inststrlen(brbeg, 1, -1);
+	pl = -1;
+	hb = 1;
+    }
+    if (sl >= 0 && i >= sl && brend && *brend) {
+	inststrlen(brend, 1, -1);
+	sl = -1;
+	hb = 1;
+    }
     while (l) {
-	if (d < 0 && (l->flags & CLF_DIFF))
-	    d = cs;
 	if (m < 0 && (l->flags & (CLF_MISS | CLF_SUF)) == (CLF_MISS | CLF_SUF))
 	    m = cs;
 	if (l->flags & CLF_MID) {
@@ -1840,6 +1848,8 @@
 	} else {
 	    inststrlen(l->line, 1, l->llen);
 	}
+	if (d < 0 && (l->flags & CLF_DIFF))
+	    d = cs;
 	if (m < 0 && (l->flags & CLF_MISS))
 	    m = cs;
 	i += l->llen;
@@ -2556,8 +2566,8 @@
 		    sl = strlen(s);
 		}
 		if (!ms && ai->firstm) {
-		    if ((i = pfxlen(ai->firstm->str, s)) < ai->prerest)
-			ai->prerest = i;
+		    if (sl < ai->minlen)
+			ai->minlen = sl;
 		    if ((i = sfxlen(ai->firstm->str, s)) < ai->suflen)
 			ai->suflen = i;
 		}
@@ -2823,8 +2833,8 @@
     if (!test)
 	return;
     if (!ms && !ispattern && ai->firstm) {
-	if ((test = sl - pfxlen(ai->firstm->str, s)) < ai->prerest)
-	    ai->prerest = test;
+	if (sl < ai->minlen)
+	    ai->minlen = sl;
 	if ((test = sfxlen(ai->firstm->str, s)) < ai->suflen)
 	    ai->suflen = test;
     }
@@ -3452,12 +3462,13 @@
 	    ms.next = NULL;
 	    ms.matcher = m->matcher;
 	    mstack = &ms;
-	}
+	} else
+	    mstack = NULL;
 	ainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
 	fainfo = (Aminfo) hcalloc(sizeof(struct aminfo));
 
-	ainfo->prerest = ainfo->suflen = 
-	    fainfo->prerest = fainfo->suflen = 10000;
+	ainfo->minlen = ainfo->suflen = 
+	    fainfo->minlen = fainfo->suflen = 10000;
 	ainfo->noipre = fainfo->noipre= 1;
 
 	freecl = NULL;
@@ -5471,7 +5482,7 @@
 	 * on the next call to completion the inserted string would be     *
 	 * taken as a match and no menu completion would be started.       */
 
-	if (isset(RECEXACT) && !lc && !ainfo->prerest)
+	if (isset(RECEXACT) && !lc && ps && ainfo->minlen == strlen(ps))
 	    am = 1;
 
 	/*

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


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re:  PATCH: zsh-3.1.5-pws-6: bash-style completion
@ 1999-02-04 14:05 Sven Wischnowsky
  1999-02-04 14:12 ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Wischnowsky @ 1999-02-04 14:05 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> I've also been having strange effects when combining all this with:
>   compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
> but I haven't tracked it down (and it's there anyway, I just normally
> use menu completion so hadn't noticed).  I think there may be a
> problem with `compctl -M' on its own, too, since I got a crash after
> that once.

Hm, I haven't found any unusual behavior here, so I guess, I need an
example.


>From the patch in do_ambiguous():

>	 * We don't do this when BASH_AUTO_LIST is set, because that would *
>	 * mean you only got a completion list the third time you hit tab  *
>	 * (or whichever key).                                             */
> 	if(isset(LISTAMBIGUOUS) && !isset(BASHAUTOLIST) && !am &&

I have only a bash-2.01.1 here but that version shows the behavior to
list the matches only on the third TAB: 1) insert unambiguous prefix,
2) do nothing, 3) show list. If the unambiguous prefix was completely
typed (not automatically inserted), it first does nothing and shows
the list on the second TAB. So I'd vote for removing the test, see the 
patch below which also fixes a typo in your patch. Otherwise using
BASHAUTOLIST will be the same as LISTAMBIGUOUS+AUTOLIST if the
unambiguous prefix had to be automatically inserted.

Bye
 Sven

--- Src/Zle/zle_tricky.c.old	Thu Feb  4 14:53:53 1999
+++ Src/Zle/zle_tricky.c	Thu Feb  4 14:59:31 1999
@@ -303,7 +303,7 @@
     else {
 	if (lastambig == 1 && isset(BASHAUTOLIST) && !usemenu && !menucmp) {
 	    docomplete(COMP_LIST_COMPLETE);
-	    lastambig == 2;
+	    lastambig = 2;
 	} else
 	    docomplete(COMP_COMPLETE);
     }
@@ -5484,7 +5484,7 @@
 	 * We don't do this when BASH_AUTO_LIST is set, because that would *
 	 * mean you only got a completion list the third time you hit tab  *
 	 * (or whichever key).                                             */
-	if(isset(LISTAMBIGUOUS) && !isset(BASHAUTOLIST) && !am &&
+	if(isset(LISTAMBIGUOUS) && !am &&
 	   (ics != cs || (ainfo->suflen && !atend))) {
 	    invalidatelist();
 	    lastambig = 0;

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


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re:  PATCH: zsh-3.1.5-pws-6: bash-style completion
@ 1999-02-04 11:48 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 1999-02-04 11:48 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> Sven Wischnowsky wrote:
> > I don't have a 3.0.5, so I couldn't try the patch. But as far as I can 
> > see, this should behave like normal completion with `setopt AUTOLIST'
> > and `setopt LISTAMBIGUOUS'.
> 
> We seem to have this discussion every week.  It's not like bash,
> because bash only shows the list on the *second* tab, and zsh can't
> currently do that.

I *know* that the thing I suggested shows behavior unlike bash. I was
referring to the patch he sent which (as far as I can see, without
testing it) should behave like LISTAMBIGUOUS plus AUTOLIST.

> Nor do I think it's fair to rely on the new
> completion to try to get this behaviour.

That's right.

> ...
>
> I've also been having strange effects when combining all this with:
>   compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
> but I haven't tracked it down (and it's there anyway, I just normally
> use menu completion so hadn't noticed).  I think there may be a
> problem with `compctl -M' on its own, too, since I got a crash after
> that once.

I'll look into this.


Bye
 Sven


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


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re:  [PATCH] bash-style completion
@ 1999-02-04  8:15 Sven Wischnowsky
  1999-02-04 11:22 ` PATCH: zsh-3.1.5-pws-6: " Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Wischnowsky @ 1999-02-04  8:15 UTC (permalink / raw)
  To: zsh-workers; +Cc: Dag-Erling Smorgrav


Dag-Erling Smorgrav wrote:

> I installed zsh 3.0.5 today and immediately liked it a lot better than
> bash2, which I'd previously been using. The only zsh feature I dislike
> is the csh-style completion (TAB to complete the unambiguous prefix,
> ^D to list possible completions), so I hacked zsh to provide
> bash-style completion (TAB completes the unambiguous prefix, TAB again
> lists possible completions). Patches against 3.0.5 are attached. Hope
> they can be of use.

I don't have a 3.0.5, so I couldn't try the patch. But as far as I can 
see, this should behave like normal completion with `setopt AUTOLIST'
and `setopt LISTAMBIGUOUS'.

> The patches also fix a minor bug (lastambig was not being reset when
> the completion list is invalidated).

This is already in all current versions of 3.1.5.

(For Dag: the most recent version is available at
`http://www.ifh.de/~pws/computing/zsh-3.1.5-pws-6.tar.gz', but it's
*very* beta.)


Bye
 Sven


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


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

end of thread, other threads:[~1999-02-05  9:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-04 14:40 PATCH: zsh-3.1.5-pws-6: bash-style completion Dag-Erling Smorgrav
  -- strict thread matches above, loose matches on Subject: below --
1999-02-05  9:51 Sven Wischnowsky
1999-02-05  8:28 Sven Wischnowsky
1999-02-05  9:17 ` Peter Stephenson
1999-02-04 14:05 Sven Wischnowsky
1999-02-04 14:12 ` Peter Stephenson
1999-02-04 15:26   ` Bart Schaefer
1999-02-04 11:48 Sven Wischnowsky
1999-02-04  8:15 [PATCH] " Sven Wischnowsky
1999-02-04 11:22 ` PATCH: zsh-3.1.5-pws-6: " Peter Stephenson

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).