about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_hist.c7
-rw-r--r--Src/Zle/zle_misc.c3
-rw-r--r--Src/Zle/zle_tricky.c59
-rw-r--r--Src/Zle/zle_vi.c2
4 files changed, 54 insertions, 17 deletions
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index 2def5f03a..0064d4ef0 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -498,6 +498,7 @@ zle_goto_hist(int ev)
     histline = ev;
     setline(t);
     setlastline();
+    clearlist = 1;
     return 1;
 }
 
@@ -515,6 +516,7 @@ pushline(void)
     stackcs = cs;
     *line = '\0';
     ll = cs = 0;
+    clearlist = 1;
 }
 
 /**/
@@ -537,9 +539,9 @@ pushlineoredit(void)
 	cs += ics;
     }
     pushline();
-    if (!isfirstln) {
+    if (!isfirstln)
 	errflag = done = 1;
-    }
+    clearlist = 1;
 }
 
 /**/
@@ -571,6 +573,7 @@ getline(void)
 	memcpy((char *)line + cs, s, cc);
 	cs += cc;
 	free(s);
+	clearlist = 1;
     }
 }
 
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index cf9aac435..e7f1744d5 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -135,6 +135,7 @@ killbuffer(void)
 {
     cs = 0;
     forekill(ll, 0);
+    clearlist = 1;
 }
 
 /**/
@@ -157,6 +158,7 @@ backwardkillline(void)
 		cs--, i++;
     }
     forekill(i, 1);
+    clearlist = 1;
 }
 
 /**/
@@ -288,6 +290,7 @@ killline(void)
 		cs++, i++;
     }
     backkill(i, 0);
+    clearlist = 1;
 }
 
 /**/
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 62c39fdc9..c303fd97d 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -1322,18 +1322,17 @@ get_comp_string(void)
 	 * as being in math.                                              */
 	if (inwhat != IN_MATH) {
 	    int i = 0;
-	    char *nb = (iident(*s) ? s : s + 1), *ne = NULL;
+	    char *nnb = (iident(*s) ? s : s + 1), *nb = NULL, *ne = NULL;
 
 	    for (tt = s; ++tt < s + cs - wb;)
 		if (*tt == Inbrack) {
 		    i++;
+		    nb = nnb;
 		    ne = tt;
 		} else if (i && *tt == Outbrack)
 		    i--;
-		else if (!iident(*tt)) {
-		    nb = tt + 1;
-		    ne = NULL;
-		}
+		else if (!iident(*tt))
+		    nnb = tt + 1;
 	    if (i) {
 		inwhat = IN_MATH;
 		insubscr = 1;
@@ -1347,12 +1346,35 @@ get_comp_string(void)
 	    }
 	}
 	if (inwhat == IN_MATH) {
-	    /* In mathematical expression, we complete parameter names (even *
-	     * if they don't have a `$' in front of them).  So we have to    *
-	     * find that name.                                               */
-	    for (we = cs; iident(line[we]); we++);
-	    for (wb = cs; --wb >= 0 && iident(line[wb]););
-	    wb++;
+	    if (compfunc) {
+		int lev;
+		char *p;
+
+		for (wb = cs - 1, lev = 0; wb > 0; wb--)
+		    if (line[wb] == ']' || line[wb] == ')')
+			lev++;
+		    else if (line[wb] == '[') {
+			if (!lev--)
+			    break;
+		    } else if (line[wb] == '(') {
+			if (!lev && line[wb - 1] == '(')
+			    break;
+			if (lev)
+			    lev--;
+		    }
+		wb++;
+		p = (char *) line + wb;
+		if (wb && (*p == '[' || *p == '(') &&
+		    !skipparens(*p, (*p == '[' ? ']' : ')'), &p))
+			we = p - (char *) line;
+	    } else {
+		/* In mathematical expression, we complete parameter names  *
+		 * (even if they don't have a `$' in front of them).  So we *
+		 * have to find that name.                                  */
+		for (we = cs; iident(line[we]); we++);
+		for (wb = cs; --wb >= 0 && iident(line[wb]););
+		wb++;
+	    }
 	    zsfree(s);
 	    s = zalloc(we - wb + 1);
 	    strncpy(s, (char *) line + wb, we - wb);
@@ -5032,6 +5054,7 @@ static void
 docompletion(char *s, int lst, int incmd)
 {
     HEAPALLOC {
+	char *opm;
 	LinkNode n;
 
 	pushheap();
@@ -5045,7 +5068,7 @@ docompletion(char *s, int lst, int incmd)
 		   ((isset(AUTOLIST) && !isset(BASHAUTOLIST)) ? 
 		    (isset(LISTAMBIGUOUS) ? 3 : 2) : 0) : 1);
 	zsfree(comppatmatch);
-	comppatmatch = ztrdup(useglob ? "yes" : "");
+	opm = comppatmatch = ztrdup(useglob ? "yes" : "");
 	zsfree(compforcelist);
 	compforcelist = ztrdup("");
 	haspattern = 0;
@@ -5057,7 +5080,7 @@ docompletion(char *s, int lst, int incmd)
 	    clearlist = 1;
 	    goto compend;
 	}
-	if (comppatmatch && *comppatmatch)
+	if (comppatmatch && *comppatmatch && comppatmatch != opm)
 	    haspattern = 1;
 	if (!useline && uselist)
 	    /* All this and the guy only wants to see the list, sigh. */
@@ -5240,14 +5263,20 @@ callcompfunc(char *s, char *fn)
 	zsfree(compprefix);
 	zsfree(compsuffix);
 	if (unset(COMPLETEINWORD)) {
-	    tmp = quotename(s, NULL, NULL, NULL);
+	    if (inwhat == IN_MATH)
+		tmp = s;
+	    else
+		tmp = quotename(s, NULL, NULL, NULL);
 	    untokenize(tmp);
 	    compprefix = ztrdup(tmp);
 	    compsuffix = ztrdup("");
 	} else {
 	    char *ss = s + offs, sav;
 	    
-	    tmp = quotename(s, &ss, NULL, NULL);
+	    if (inwhat == IN_MATH)
+		tmp = s;
+	    else
+		tmp = quotename(s, &ss, NULL, NULL);
 	    sav = *ss;
 	    *ss = '\0';
 	    untokenize(tmp);
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 2e4fb4a32..5b1548e25 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -535,6 +535,7 @@ viopenlinebelow(void)
     spaceinline(1);
     line[cs++] = '\n';
     startvitext(1);
+    clearlist = 1;
 }
 
 /**/
@@ -545,6 +546,7 @@ viopenlineabove(void)
     spaceinline(1);
     line[cs] = '\n';
     startvitext(1);
+    clearlist = 1;
 }
 
 /**/