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

Re: Re: [rr13@xxxxxxxxxxxxxxxxxxxxxx: Bug#276187: zsh: Ineractive menu completion with tab doesnt work.]



> If you type TAB again in this mode, though, it's not clear what should
> happen.

Indeed.

> If you've already begun to disambiguate, typing TAB does nothing.  

I think it's actually missing a trick here, which what was confusing me
about what TAB ought to be doing.  If you type "l", then TAB, and that
enters interactive completion, and all the completions start with
"langinfo", it should insert "langinfo", but it doesn't.  That's because it
doesn't have enough information about the state at the start.  If you type
"a", then TAB, it does insert the remaining string.

I haven't looked at this.  That's to say, I've looked at this enough to be
able to decide I wasn't going to look at it further for the time being.

> The bug happens when you type TAB immediately after entering interactive
> completion, before any disambiguation has occurred.  I suspect in this
> case it's fine just to drop straight back into normal menulist completion
> and cancel interactive mode.  (Ideally that would happen even after the
> disambiguation has begun, too, rather than have TAB be a no-op there.)

I actually implemented that unconditionally on a TAB, before I realised
that TAB should normally insert the unambiguous prefix.  So I haven't
changed this and currently it just does nothing at that point.  I think it
should insert the rest of the unambiguous prefix and if you're expecting
that to happen, having it instead enter normal menu selection is probably
too confusing.  (But maybe it isn't, since what it would insert is already
in the "interactive" promt, and you can see in this case it matches what's
already on the command line.)  Probably it needs another test rather than
do this the way I originally changed it.

Here's what I've got.  This currently seems to work the way it's been
implemented, but that may not be ideal.  The dupstring(line) is the key
part.  The rest is just comments.

This is pasted into webmail, so it might not apply cleanly.  However, if it looks OK I
can commit it tomorrow.

Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.60
diff -u -r1.60 complist.c
--- Src/Zle/complist.c	2 Jun 2004 22:15:01 -0000	1.60
+++ Src/Zle/complist.c	13 Oct 2004 16:40:12 -0000
@@ -1730,8 +1730,18 @@
     int cs, acc, nmatches, mline, mlbeg, nolist;
     struct menuinfo info;
     Cmgroup amatches, pmatches, lastmatches, lastlmatches;
+    /*
+     * Status for how line looked like previously.
+     */
     char *origline;
     int origcs, origll;
+    /*
+     * Status for interactive mode.  status is the line
+     * printed above the matches saying what the interactive
+     * completion prefix is.  mode says whether we are in
+     * interactive or some search mode.
+     * typed.
+     */
     char *status;
     int mode;
 };
@@ -1925,6 +1935,9 @@
     return NULL;
 }
 
+/*
+ * Values to assign to mode: interactive, etc.
+ */
 #define MM_INTER   1
 #define MM_FSEARCH 2
 #define MM_BSEARCH 3
@@ -1972,6 +1985,14 @@
         if (!strcmp(s, "interactive")) {
             int l = strlen(origline);
 
+	    /*
+	     * In interactive completion mode we don't insert
+	     * the completion onto the command line, instead
+	     * we show just what the user has typed and
+	     * the match so far underneath (stored in "status").
+	     * So put the command line back to how it
+	     * was before completion started.
+	     */
             mode = MM_INTER;
             cs = 0;
             foredel(ll);
@@ -2062,7 +2083,16 @@
         if (first && !listshown && isset(LISTBEEP))
             zbeep();
         if (first) {
-            modeline = dyncat(complastprefix, complastsuffix);
+	    /*
+	     * remember the original data that we will use when
+	     * performing interactive completion to restore the
+	     * command line when a menu completion is inserted.
+	     * this is because menu completion will insert
+	     * the next match in the loop; for interactive
+	     * completion we don't want that, we always want to
+	     * be able to type the next character.
+	     */
+	    modeline = dupstring(line);
             modecs = cs;             modell = ll;
             modelen = minfo.len;
@@ -2152,6 +2182,11 @@
             else {
                 int l = strlen(origline);
 
+		/*
+		 * Entering interactive completion mode:
+		 * same code as when we enter it on menu selection
+		 * start.
+		 */
                 mode = MM_INTER;
                 cs = 0;
                 foredel(ll);
@@ -2205,6 +2240,13 @@
             if (cmd != Th(z_acceptandinfernexthistory)) {
                 int l = strlen(origline);
 
+		/*
+		 * Interactive mode: we need to restore the
+		 * line, add the character, then remember how
+		 * this new line looks in order to keep
+		 * the command line as it is with just the
+		 * characters typed by the user.
+		 */
                 cs = 0;
                 foredel(ll);
                 spaceinline(l);
@@ -2699,6 +2741,12 @@
 		   !strcmp(cmd->nam, "menu-complete") ||
 		   !strcmp(cmd->nam, "menu-expand-or-complete")) {
             if (mode == MM_INTER) {
+		/*
+		 * do_menucmp() has inserted the completion onto
+		 * the command line.  In interactive mode we
+		 * don't want that, just what the user typed,
+		 * so restore the information.
+		 */
                 origline = modeline;
                 origcs = modecs;
                 origll = modell;

pws


-- 

Whatever you Wanadoo:
http://www.wanadoo.co.uk/time/

This email has been checked for most known viruses - find out more at: http://www.wanadoo.co.uk/help/id/7098.htm



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