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

Re: Menu selection



Hi

Felix mailed me again to say that he still got a crash. I couldn't
reproduce it anymore, but hope the patch below finally fixes it.
Felix, does it?

The patch also fixes problems in the command line display when using
interactive mode, e.g. after ${<TAB>.


Bye
  Sven

Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.62
diff -u -r1.62 compcore.c
--- Src/Zle/compcore.c	1 Jul 2002 08:25:17 -0000	1.62
+++ Src/Zle/compcore.c	4 Jul 2002 09:22:27 -0000
@@ -670,6 +670,10 @@
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
+        zsfree(complastprefix);
+        zsfree(complastsuffix);
+        complastprefix = ztrdup(compprefix);
+        complastsuffix = ztrdup(compsuffix);
 	zsfree(compiprefix);
 	zsfree(compisuffix);
 	if (parwb < 0) {
Index: Src/Zle/complete.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complete.c,v
retrieving revision 1.21
diff -u -r1.21 complete.c
--- Src/Zle/complete.c	24 Apr 2002 07:59:19 -0000	1.21
+++ Src/Zle/complete.c	4 Jul 2002 09:22:27 -0000
@@ -46,6 +46,8 @@
      **compredirs,
      *compprefix,
      *compsuffix,
+     *complastprefix,
+     *complastsuffix,
      *compisuffix,
      *compqiprefix,
      *compqisuffix,
@@ -1405,6 +1407,8 @@
 	compexact = compexactstr = comppatmatch = comppatinsert =
 	complastprompt = comptoend = compoldlist = compoldins =
 	compvared = compqstack = NULL;
+    complastprefix = ztrdup("");
+    complastsuffix = ztrdup("");
     complistmax = 0;
     hascompmod = 1;
 
@@ -1458,6 +1462,8 @@
 	freearray(compredirs);
     zsfree(compprefix);
     zsfree(compsuffix);
+    zsfree(complastprefix);
+    zsfree(complastsuffix);
     zsfree(compiprefix);
     zsfree(compisuffix);
     zsfree(compqiprefix);
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.52
diff -u -r1.52 complist.c
--- Src/Zle/complist.c	3 Jul 2002 07:59:59 -0000	1.52
+++ Src/Zle/complist.c	4 Jul 2002 09:22:27 -0000
@@ -1752,7 +1752,8 @@
 #define MAX_STATUS 128
 
 static char *
-setmstatus(char *status, int *csp, int *llp, int *lenp)
+setmstatus(char *status, char *sline, int sll, int scs,
+           int *csp, int *llp, int *lenp)
 {
     char *p, *s, *ret = NULL;
     int pl, sl, max;
@@ -1771,17 +1772,14 @@
         strncpy(s, (char *) line + cs, lastend - cs);
         s[lastend - cs] = '\0';
 
-        cs = wb;
-        foredel(lastend - wb);
-        pl = strlen(compprefix);
-        sl = strlen(compsuffix);
-        spaceinline(pl + sl);
-        strncpy(line + wb, compprefix, pl);
-        strncpy(line + wb + pl, compsuffix, sl);
-        cs = wb + pl;
+        cs = 0;
+        foredel(ll);
+        spaceinline(sll);
+        memcpy(line, sline, sll);
+        cs = scs;
     } else {
-        p = compprefix;
-        s = compsuffix;
+        p = complastprefix;
+        s = complastsuffix;
     }
     pl = strlen(p);
     sl = strlen(s);
@@ -1973,7 +1971,7 @@
             spaceinline(l);
             strncpy((char *) line, origline, l);
             cs = origcs;
-            setmstatus(status, NULL, NULL, NULL);
+            setmstatus(status, NULL, 0 , 0, NULL, NULL, NULL);
         } else if (strpfx("search", s)) {
             mode = (strstr(s, "back") ? MM_BSEARCH : MM_FSEARCH);
         }
@@ -2056,7 +2054,7 @@
         if (first && !listshown && isset(LISTBEEP))
             zbeep();
         if (first) {
-            modeline = dyncat(compprefix, compsuffix);
+            modeline = dyncat(complastprefix, complastsuffix);
             modecs = cs;
             modell = ll;
             modelen = minfo.len;
@@ -2141,13 +2139,16 @@
                 spaceinline(l);
                 strncpy((char *) line, origline, l);
                 cs = origcs;
-                setmstatus(status, NULL, NULL, NULL);
+                setmstatus(status, NULL, 0, 0, NULL, NULL, NULL);
 
                 continue;
             }
 	} else if (cmd == Th(z_acceptandinfernexthistory) ||
                    (mode == MM_INTER && (cmd == Th(z_selfinsert) ||
                                          cmd == Th(z_selfinsertunmeta)))) {
+            char *saveline = NULL;
+            int savell;
+            int savecs;
 	    Menustack s = (Menustack) zhalloc(sizeof(*s));
 
 	    s->prev = u;
@@ -2195,15 +2196,27 @@
                 else
                     selfinsertunmeta(zlenoargs);
 
+                saveline = (char *) zhalloc(ll);
+                memcpy(saveline, line, ll);
+                savell = ll;
+                savecs = cs;
                 iforcemenu = -1;
             } else
                 mode = 0;
 	    menucomplete(zlenoargs);
 	    iforcemenu = 0;
 
-	    if ((dat ? dat->num : nmatches) < 1 || !minfo.cur || !*(minfo.cur)) {
+            if (cmd != Th(z_acceptandinfernexthistory))
+                modeline = setmstatus(status, saveline, savell, savecs,
+                                      &modecs, &modell, &modelen);
+
+	    if (nmatches < 1 || !minfo.cur || !*(minfo.cur)) {
 		nolist = 1;
-		if ((dat ? (dat->nmesg || nmessages) : nmessages)) {
+                if (mode == MM_INTER) {
+                    statusline = status;
+                    statusll = strlen(status);
+                }
+		if (nmessages) {
 		    showinglist = -2;
 		    zrefresh();
 		} else {
@@ -2219,11 +2232,11 @@
 		    zrefresh();
 		    showinglist = clearlist = 0;
 		}
+                statusline = NULL;
+                statusll = 0;
+
 		goto getk;
 	    }
-            if (cmd != Th(z_acceptandinfernexthistory))
-                modeline = setmstatus(status, &modecs, &modell, &modelen);
-
 	    clearlist = listshown = 1;
 	    mselect = (*(minfo.cur))->gnum;
 	    setwish = wasnext = 1;

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



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