about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/compcore.c4
-rw-r--r--Src/Zle/complete.c6
-rw-r--r--Src/Zle/complist.c51
3 files changed, 42 insertions, 19 deletions
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index e0aef2864..06229cfc7 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -670,6 +670,10 @@ callcompfunc(char *s, char *fn)
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
+        zsfree(complastprefix);
+        zsfree(complastsuffix);
+        complastprefix = ztrdup(compprefix);
+        complastsuffix = ztrdup(compsuffix);
 	zsfree(compiprefix);
 	zsfree(compisuffix);
 	if (parwb < 0) {
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index e1051c30c..ef029ddcb 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -46,6 +46,8 @@ char **compwords,
      **compredirs,
      *compprefix,
      *compsuffix,
+     *complastprefix,
+     *complastsuffix,
      *compisuffix,
      *compqiprefix,
      *compqisuffix,
@@ -1405,6 +1407,8 @@ setup_(Module m)
 	compexact = compexactstr = comppatmatch = comppatinsert =
 	complastprompt = comptoend = compoldlist = compoldins =
 	compvared = compqstack = NULL;
+    complastprefix = ztrdup("");
+    complastsuffix = ztrdup("");
     complistmax = 0;
     hascompmod = 1;
 
@@ -1458,6 +1462,8 @@ finish_(Module m)
 	freearray(compredirs);
     zsfree(compprefix);
     zsfree(compsuffix);
+    zsfree(complastprefix);
+    zsfree(complastsuffix);
     zsfree(compiprefix);
     zsfree(compisuffix);
     zsfree(compqiprefix);
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 22e994863..417006a87 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1752,7 +1752,8 @@ struct menusearch {
 #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 @@ setmstatus(char *status, int *csp, int *llp, int *lenp)
         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 @@ domenuselect(Hookdef dummy, Chdata dat)
             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 @@ domenuselect(Hookdef dummy, Chdata dat)
         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 @@ domenuselect(Hookdef dummy, Chdata dat)
                 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 @@ domenuselect(Hookdef dummy, Chdata dat)
                 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 @@ domenuselect(Hookdef dummy, Chdata dat)
 		    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;