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

PATCH: Re: And another thing



Peter Stephenson wrote:

> _expand_word (^xe) is also behaving weirdly with select-menu when there is
> more than a page to display; it seems to flash up the completion list but
> do nothing else.  _expand_word_list (^xd) works fine.  It also seems to be
> tying itself (or rather the display) in knots trying to display the string
> for all expansions, which, not surprisingly, is rather long in this case.

Urgh. Menu-selection with matches spanning more than one line and
scrolling was serverly broken. This fixes it for me, but I had to
disable a piece of code I liked: the code that tries to ensure that
the explanation strings are scrolled onto the screen when in the first 
line below them. I'll have to do some more work to get that back.

The patch also modifies _expand to display only a shorter string for
`all expansions' when it would be longer than the screen-width. I
wanted to do that for quite some time anyway. Hope that's OK for
everyone.


Bye
 Sven

Index: Completion/Core/_expand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_expand,v
retrieving revision 1.10
diff -u -r1.10 _expand
--- Completion/Core/_expand	2000/05/08 08:44:54	1.10
+++ Completion/Core/_expand	2000/05/16 10:29:46
@@ -108,9 +108,17 @@
 else
   _tags all-expansions expansions original
 
-  _requested all-expansions expl 'all expansions' &&
-      compadd "$expl[@]" -UQ -qS "$suf" - "$exp"
+  if _requested all-expansions expl 'all expansions'; then
+    local disp dstr
 
+    if [[ $#exp -ge COLUMNS ]]; then
+      disp=( -ld dstr )
+      dstr=( "${(r:COLUMNS-5:)exp} ..." )
+    else
+      disp=()
+    fi
+    compadd "$disp[@]" "$expl[@]" -UQ -qS "$suf" - "$exp"
+  fi
   if [[ $#exp -gt 1 ]] && _requested expansions; then
     local i normal dir
 
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.20
diff -u -r1.20 compcore.c
--- Src/Zle/compcore.c	2000/05/15 11:55:38	1.20
+++ Src/Zle/compcore.c	2000/05/16 10:29:47
@@ -507,6 +507,7 @@
 	if ((ret = runhookdef(MENUSTARTHOOK, (void *) &dat))) {
 	    menucmp = menuacc = 0;
 	    if (ret == 2) {
+		fixsuffix();
 		cs = 0;
 		foredel(ll);
 		inststr(origline);
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.16
diff -u -r1.16 complist.c
--- Src/Zle/complist.c	2000/05/16 08:05:15	1.16
+++ Src/Zle/complist.c	2000/05/16 10:29:47
@@ -384,6 +384,7 @@
 static int noselect, mselect, inselect, mcol, mline, mcols, mlines, mmlen;
 static int selected, mlbeg = -1, mlend = 9999999, mscroll, mrestlines;
 static int mnew, mlastcols, mlastlines, mhasstat, mfirstl, mlastm;
+static int mlprinted;
 static char *mstatus, *mlistp;
 static Cmatch **mtab, **mmtabp;
 static Cmgroup *mgtab, *mgtabp;
@@ -533,7 +534,7 @@
 static int
 clnicezputs(Listcols c, char *s, int ml)
 {
-    int cc, i = 0, col = 0, ask;
+    int cc, i = 0, col = 0, ask, oml = ml;
     char *t;
 
     initiscol(c);
@@ -550,18 +551,22 @@
 	    cc = *s++ ^ 32;
 
 	for (t = nicechar(cc); *t; t++) {
-	    if (ml == mlend - 1 && col == columns - 1)
+	    if (ml == mlend - 1 && col == columns - 1) {
+		mlprinted = ml - oml;
 		return 0;
+	    }
 	    putc(*t, shout);
 	    if (++col == columns) {
 		ml++;
-		if (mscroll && !--mrestlines && (ask = asklistscroll(ml)))
+		if (mscroll && !--mrestlines && (ask = asklistscroll(ml))) {
+		    mlprinted = ml - oml;
 		    return ask;
-
+		}
 		col = 0;
 	    }
 	}
     }
+    mlprinted = ml - oml;
     return 0;
 }
 
@@ -727,8 +732,10 @@
 
     if ((stat = !fmt)) {
 	if (mlbeg >= 0) {
-	    if (!(fmt = mstatus))
+	    if (!(fmt = mstatus)) {
+		mlprinted = 0;
 		return 0;
+	    }
 	    cc = -1;
 	} else
 	    fmt = mlistp;
@@ -881,7 +888,7 @@
 		    *stop = 1;
 		    if (stat && n)
 			mfirstl = -1;
-		    return l + (cc / columns);
+		    return (mlprinted = l + (cc / columns));
 		}
 	    }
 	}
@@ -892,7 +899,7 @@
     if (stat && n)
 	mfirstl = -1;
 
-    return l + (cc / columns);
+    return (mlprinted = l + (cc / columns));
 }
 
 /* This is like zputs(), but allows scrolling. */
@@ -932,7 +939,7 @@
 static int
 compnicezputs(char *s, int ml)
 {
-    int c, col = 0, ask;
+    int c, col = 0, ask, oml = ml;
     char *t;
 
     while ((c = *s++)) {
@@ -946,18 +953,22 @@
 	    c = *s++ ^ 32;
 
 	for (t = nicechar(c); *t; t++) {
-	    if (ml == mlend - 1 && col == columns - 1)
+	    if (ml == mlend - 1 && col == columns - 1) {
+		mlprinted = ml - oml;
 		return 0;
+	    }
 	    putc(*t, shout);
 	    if (++col == columns) {
 		ml++;
-		if (mscroll && !--mrestlines && (ask = asklistscroll(ml)))
+		if (mscroll && !--mrestlines && (ask = asklistscroll(ml))) {
+		    mlprinted = ml - oml;
 		    return ask;
-
+		}
 		col = 0;
 	    }
 	}
     }
+    mlprinted = ml - oml;
     return 0;
 }
 
@@ -1024,6 +1035,14 @@
 			mfirstl = ml;
 		    l = compprintfmt((*e)->str, (*e)->count, dolist(ml), 1,
 				     ml, &stop);
+		    if (mselect >= 0) {
+			int mm = (mcols * ml), i;
+
+			for (i = mcols; i--; ) {
+			    mtab[mm + i] = NULL;
+			    mgtab[mm + i] = NULL;
+			}
+		    }
 		    if (stop)
 			goto end;
 		    if (!lasttype && ml >= mlbeg) {
@@ -1035,8 +1054,8 @@
 			lastp = NULL;
 			lastused = 1;
 		    }
-		    ml += l;
-		    if (dolistcl(ml) && cl >= 0 && (cl -= l) <= 1) {
+		    ml += mlprinted;
+		    if (dolistcl(ml) && cl >= 0 && (cl -= mlprinted) <= 1) {
 			cl = -1;
 			if (tccan(TCCLEAREOD))
 			    tcout(TCCLEAREOD);
@@ -1155,6 +1174,12 @@
 			    printed++;
 			if (clprintm(g, p, 0, ml, 1, 0, NULL, NULL))
 			    goto end;
+			ml += mlprinted;
+			if (dolistcl(ml) && (cl -= mlprinted) <= 1) {
+			    cl = -1;
+			    if (tccan(TCCLEAREOD))
+				tcout(TCCLEAREOD);
+			}
 			pnl = 1;
 		    }
 		    if (!mnew && ml > mlend)
@@ -1220,6 +1245,12 @@
 
 		    if (dolist(ml))
 			printed++;
+		    ml += mlprinted;
+		    if (dolistcl(ml) && (cl -= mlprinted) < 1) {
+			cl = -1;
+			if (tccan(TCCLEAREOD))
+			    tcout(TCCLEAREOD);
+		    }
 		    if (mfirstl < 0)
 			mfirstl = ml;
 
@@ -1321,6 +1352,7 @@
 		putc(' ', shout);
 	    zcoff();
 	}
+	mlprinted = 0;
 	return 0;
     }
     m = *mp;
@@ -1334,8 +1366,10 @@
 		mgtab[mm + i] = g;
 	    }
 	}
-	if (!dolist(ml))
+	if (!dolist(ml)) {
+	    mlprinted = printfmt(m->disp, 0, 0, 0) / columns;
 	    return 0;
+	}
 	if (m->gnum == mselect) {
 	    int mm = (mcols * ml);
 	    mline = ml;
@@ -1377,8 +1411,10 @@
 		mgtab[mx + mm + i] = g;
 	    }
 	}
-	if (!dolist(ml))
+	if (!dolist(ml)) {
+	    mlprinted = niceztrlen(m->disp ? m->disp : m->str) / columns;
 	    return 0;
+	}
 	if (m->gnum == mselect) {
 	    int mm = mcols * ml;
 
@@ -1406,6 +1442,7 @@
 	    return 1;
 	}
 	len = niceztrlen(m->disp ? m->disp : m->str);
+	mlprinted = len / columns;
 
 	 if (isset(LISTTYPES) && buf) {
 	    if (m->gnum != mselect) {
@@ -1571,7 +1608,7 @@
     Thingy cmd;
     Menustack u = NULL;
     int i = 0, acc = 0, wishcol = 0, setwish = 0, oe = onlyexpl, wasnext = 0;
-    int space, lbeg = 0, step = 1, wrap;
+    int space, lbeg = 0, step = 1, wrap, pl = nlnct;
     char *s;
 
     if (fdat || (dummy && (!(s = getsparam("MENUSELECT")) ||
@@ -1620,11 +1657,13 @@
 	    if (y < mlines)
 		mline = y;
 	}
-	space = lines - nlnct - mhasstat;
+	space = lines - pl - mhasstat;
 	while (mline < mlbeg)
 	    if ((mlbeg -= step) < 0)
 		mlbeg = 0;
-
+#if 0
+	/* Attempt to ensure that the explanations for groups are scrolled
+	 * in. Doesn't work because there are other NULL fields. */
 	if (mlbeg && lbeg != mlbeg) {
 	    Cmatch **p = mtab + ((mlbeg - 1) * columns), **q;
 	    int c;
@@ -1639,10 +1678,24 @@
 		mlbeg--;
 	    }
 	}
+#endif
 	while (mline >= mlbeg + space)
 	    if ((mlbeg += step) + space > mlines)
 		mlbeg = mlines - space;
+	if (lbeg != mlbeg) {
+	    Cmatch **p = mtab + (mlbeg * columns), **q;
+	    int c;
 
+	    while (mlbeg < mlines) {
+		for (q = p, c = columns; c; q++, c--)
+		    if (*q)
+			break;
+		if (c)
+		    break;
+		p += columns;
+		mlbeg++;
+	    }
+	}
 	lbeg = mlbeg;
 	onlyexpl = 0;
 	showinglist = -2;
@@ -1877,7 +1930,7 @@
 		   cmd == Th(z_viforwardword) ||
 		   cmd == Th(z_viforwardwordend) ||
 		   cmd == Th(z_forwardword)) {
-	    int i = lines - nlnct - 1, oi = i, ll = 0;
+	    int i = lines - pl - 1, oi = i, ll = 0;
 	    Cmatch **lp = NULL;
 
 	    if (mline == mlines - 1)
@@ -1904,7 +1957,7 @@
 	} else if (cmd == Th(z_emacsbackwardword) ||
 		   cmd == Th(z_vibackwardword) ||
 		   cmd == Th(z_backwardword)) {
-	    int i = lines - nlnct - 1, oi = i, ll = 0;
+	    int i = lines - pl - 1, oi = i, ll = 0;
 	    Cmatch **lp = NULL;
 
 	    if (!mline)

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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