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

PATCH: fixes for math environments



There were a couple of bugs/problems:

- completion inside `$((...))' didn't work because the code thought it
  were in a command substitution
- subscripts inside math environments weren't detected
- completion inside `foo[...' (without a `$') didn't set
  `compstate[parameter]'


Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Thu Mar 11 14:31:02 1999
+++ Src/Zle/zle_tricky.c	Thu Mar 11 16:39:33 1999
@@ -1244,16 +1244,20 @@
 	inpop();
 	errflag = zleparse = 0;
 	if (parbegin != -1) {
-	    /* We are in command or process substitution */
+	    /* We are in command or process substitution if we are not in
+	     * a $((...)). */
 	    if (parend >= 0 && !tmp)
 		line = (unsigned char *) dupstring(tmp = (char *)line);
 	    linptr = (char *) line + ll + addedx - parbegin + 1;
-	    if (parend >= 0) {
-		ll -= parend;
-		line[ll + addedx] = '\0';
+	    if ((linptr - (char *) line) < 2 ||
+		linptr[-1] != '(' || linptr[-2] != '$') {
+		if (parend >= 0) {
+		    ll -= parend;
+		    line[ll + addedx] = '\0';
+		}
+		lexrestore();
+		goto start;
 	    }
-	    lexrestore();
-	    goto start;
 	}
 
 	if (inwhat == IN_MATH)
@@ -1315,25 +1319,23 @@
 	 * foo[_ wrong (note no $).  If we are in a subscript, treat it   *
 	 * as being in math.                                              */
 	if (inwhat != IN_MATH) {
-	    int i = 0, hn = 0;
-	    char *nb = (*s == String ? s + 1 : NULL), *ne = NULL;
+	    int i = 0;
+	    char *nb = (iident(*s) ? s : s + 1), *ne = NULL;
 
 	    for (tt = s; ++tt < s + cs - wb;)
-		if (*tt == String) {
-		    hn = 0;
-		    nb = tt + 1;
-		} else if (*tt == Inbrack) {
+		if (*tt == Inbrack) {
 		    i++;
-		    if (nb && !hn) {
-			hn = 1;
-			ne = tt;
-		    }
+		    ne = tt;
 		} else if (i && *tt == Outbrack)
 		    i--;
+		else if (!iident(*tt)) {
+		    nb = tt + 1;
+		    ne = NULL;
+		}
 	    if (i) {
 		inwhat = IN_MATH;
 		insubscr = 1;
-		if (hn && nb && ne) {
+		if (nb < ne) {
 		    char sav = *ne;
 		    *ne = '\0';
 		    zsfree(varname);
@@ -1353,6 +1355,19 @@
 	    s = zalloc(we - wb + 1);
 	    strncpy(s, (char *) line + wb, we - wb);
 	    s[we - wb] = '\0';
+	    if (wb > 2 && line[wb - 1] == '[' && iident(line[wb - 2])) {
+		int i = wb - 3;
+		unsigned char sav = line[wb - 1];
+
+		while (i >= 0 && iident(line[i]))
+		    i--;
+
+		line[wb - 1] = '\0';
+		zsfree(varname);
+		varname = ztrdup((char *) line + i + 1);
+		line[wb - 1] = sav;
+		insubscr = 1;
+	    }
 	}
 	/* This variable will hold the current word in quoted form. */
 	qword = ztrdup(s);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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