zsh-workers
 help / color / mirror / code / Atom feed
* Re: command completion taking ages
@ 2000-03-14 15:27 Sven Wischnowsky
  2000-03-14 18:32 ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-14 15:27 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Oliver Kiddle wrote:
> 
> > If I press tab in a position where all commands are completed, I get a
> > very long delay. This is quite annoying even though I can interrupt it
> > with Ctrl-C. Is there a way using the zstyle, tags and _wanted stuff
> > that I could indicate with zstyle that I don't want to complete commands
> > if $#PREFIX = 0. I couldn't see any styles which are passed through eval
> > in any of _requested, _wanted, _tags etc but other than using the
> > high-level stuff for tag ordering, I don't fully understand the tag
> > selection stuff so I may well have missed something.
> 
> No, we don't have something like that. I don't remember exactly when
> it was, but I have been thinking about something like that too...
> 
> ...
> 
> Back to your question: currently you can only 1) use tag-order to make 
> it generate as few matches as possible, or 2) (probably better) copy
> and modify _command_names to test [[ -z $PREFIX] (or (( $#PREFIX )) if 
> you prefer).

Ahem, I'm thinking too much about styles already. Of course there is a 
way:

  zstyle ':completion:*:*:-command-:*' tag-order 'maybe()' -

  maybe() { [[ -n $PREFIX ]] && comptry "$@" }

or somthing like this:

  maybe() {
    if [[ -n "$PREFIX$SUFFIX" || $1 = messages ]]; then
      comptry "$@"
    else
      _message 'not with an empty word...'
    fi
  }

Good enough?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
  2000-03-14 15:27 command completion taking ages Sven Wischnowsky
@ 2000-03-14 18:32 ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2000-03-14 18:32 UTC (permalink / raw)
  To: zsh-workers

On Mar 14,  4:27pm, Sven Wischnowsky wrote:
} Subject: Re: command completion taking ages
}
}   zstyle ':completion:*:*:-command-:*' tag-order 'maybe()' -
} 
}   maybe() { [[ -n $PREFIX ]] && comptry "$@" }

I wondered about that, but it's not a general solution for cases where
there are multiple tags and you DO want to order them when there IS a
non-empty prefix/suffix.  Is there some way for the function to say
"I didn't generate any matches, but don't try any more tags even so"?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
@ 2000-03-20 10:28 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-20 10:28 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> Oliver Kiddle wrote:
> 
> > If I press tab in a position where all commands are completed, I get a
> > very long delay.
> 
> And of course we should have a look why this is so slow...

Another reason why large lists can be slow is LIST_PACKED. For it to
work we have to repeatedly calculate the lines/columns needed while
trying to squeeze them together. The code used a rather simple
approach, just trying one possible value after another to find the
optimum. This patch makes it use a binary search instead.

And then there are two hunks for `might be used uninitialized' warnings.

Bye
 Sven

diff -ru ../z.old/Src/Zle/compresult.c Src/Zle/compresult.c
--- ../z.old/Src/Zle/compresult.c	Mon Mar 20 11:07:01 2000
+++ Src/Zle/compresult.c	Mon Mar 20 11:14:54 2000
@@ -1288,9 +1288,11 @@
 	}
     }
     if (!onlyexpl) {
+	char **pp;
+	int *ws, tlines, tline, tcols, maxlen, nth, width, glines;
+
 	for (g = amatches; g; g = g->next) {
-	    char **pp;
-	    int glines = 0;
+	    glines = 0;
 
 	    zfree(g->widths, 0);
 	    g->widths = NULL;
@@ -1332,11 +1334,6 @@
 	    g->lins = glines;
 	    nlines += glines;
 	}
-    }
-    if (!onlyexpl) {
-	char **pp;
-	int *ws, tlines, tline, tcols, maxlen, nth, width;
-
 	for (g = amatches; g; g = g->next) {
 	    if (!(g->flags & CGF_PACKED))
 		continue;
@@ -1357,9 +1354,11 @@
 
 		    if (g->flags & CGF_ROWS) {
 			int count, tcol, first, maxlines = 0, llines;
+			int beg = columns / g->shortest, end = g->cols;
+
+			while (1) {
+			    tcols = (beg + end) >> 1;
 
-			for (tcols = columns / g->shortest; tcols > g->cols;
-			     tcols--) {
 			    for (nth = first = maxlen = width = maxlines =
 				     llines = tcol = 0,
 				     count = g->dcount;
@@ -1383,17 +1382,33 @@
 				ws[tcol++] = maxlen;
 				width += maxlen;
 			    }
-			    if (!count && width < columns)
+			    if (!count && width < columns &&
+				(tcols <= 0 || beg == end))
 				break;
+
+			    if (beg == end) {
+				beg--;
+				end--;
+			    } else if (width < columns) {
+				if ((end = tcols) == beg - 1)
+				    end++;
+			    } else {
+				if ((beg = tcols) - 1 == end)
+				    end++;
+			    }
 			}
 			if (tcols > g->cols)
 			    tlines = maxlines;
 		    } else {
-			for (tlines = ((g->totl + columns) / columns);
-			     tlines < g->lins; tlines++) {
+			int beg = ((g->totl + columns) / columns);
+			int end = g->lins;
+
+			while (1) {
+			    tlines = (beg + end) >> 1;
+
 			    for (pp = g->ylist, nth = tline = width =
 				     maxlen = tcols = 0;
-				 *pp; nth++, pp++) {
+				 *pp; pp++) {
 				if (ylens[nth] > maxlen)
 				    maxlen = ylens[nth];
 				if (++tline == tlines) {
@@ -1402,23 +1417,40 @@
 				    ws[tcols++] = maxlen;
 				    maxlen = tline = 0;
 				}
+				nth++;
 			    }
 			    if (tline) {
 				ws[tcols++] = maxlen;
 				width += maxlen;
 			    }
-			    if (nth == yl && width < columns)
+			    if (nth == yl && width < columns &&
+				(beg == end || tlines >= g->lins))
 				break;
+
+			    if (beg == end) {
+				beg++;
+				end++;
+			    } else if (width < columns) {
+				if ((end = tlines) == beg + 1)
+				    end--;
+			    } else {
+				if ((beg = tlines) + 1 == end)
+				    end--;
+			    }
 			}
+			if (tlines > g->lins)
+			    tlines = g->lins;
 		    }
 		}
 	    } else if (g->width) {
 		if (g->flags & CGF_ROWS) {
 		    int addlen, count, tcol, maxlines = 0, llines, i;
+		    int beg = columns / g->shortest, end = g->cols;
 		    Cmatch *first;
 
-		    for (tcols = columns / g->shortest; tcols > g->cols;
-			 tcols--) {
+		    while (1) {
+			tcols = (beg + end) >> 1;
+
 			p = first = skipnolist(g->matches, showall);
 			for (maxlen = width = maxlines = llines = tcol = 0,
 				 count = g->dcount;
@@ -1448,8 +1480,20 @@
 			    ws[tcol++] = maxlen;
 			    width += maxlen;
 			}
-			if (!count && width < columns)
+			if (!count && width < columns &&
+			    (tcols <= 0 || beg == end))
 			    break;
+
+			if (beg == end) {
+			    beg--;
+			    end--;
+			} else if (width < columns) {
+			    if ((end = tcols) == beg - 1)
+				end++;
+			} else {
+			    if ((beg = tcols) - 1 == end)
+				end++;
+			}
 		    }
 		    if (tcols > g->cols)
 			tlines = maxlines;
@@ -1457,12 +1501,15 @@
 		    int addlen;
 		    int smask = ((showall ? 0 : (CMF_NOLIST | CMF_MULT)) |
 				 CMF_HIDE);
+		    int beg = ((g->totl + columns) / columns);
+		    int end = g->lins;
+
+		    while (1) {
+			tlines = (beg + end) >> 1;
 
-		    for (tlines = ((g->totl + columns) / columns);
-			 tlines < g->lins; tlines++) {
 			for (p = g->matches, nth = tline = width =
 				 maxlen = tcols = 0;
-			     (m = *p); p++, nth++) {
+			     (m = *p); p++) {
 			    if (!(m->flags &
 				  (m->disp ? (CMF_DISPLINE | CMF_HIDE) :
 				   smask))) {
@@ -1475,15 +1522,30 @@
 				    ws[tcols++] = maxlen;
 				    maxlen = tline = 0;
 				}
+				nth++;
 			    }
 			}
 			if (tline) {
 			    ws[tcols++] = maxlen;
 			    width += maxlen;
 			}
-			if (nth == g->dcount && width < columns)
+			if (nth == g->dcount && width < columns &&
+			    (beg == end || tlines >= g->lins))
 			    break;
+
+			if (beg == end) {
+			    beg++;
+			    end++;
+			} else if (width < columns) {
+			    if ((end = tlines) == beg + 1)
+				end--;
+			} else {
+			    if ((beg = tlines) + 1 == end)
+				end--;
+			}
 		    }
+		    if (tlines > g->lins)
+			tlines = g->lins;
 		}
 	    }
 	    if (tlines == g->lins) {
diff -ru ../z.old/Src/init.c Src/init.c
--- ../z.old/Src/init.c	Mon Mar 20 11:06:56 2000
+++ Src/init.c	Mon Mar 20 11:14:52 2000
@@ -896,7 +896,7 @@
 source(char *s)
 {
     Eprog prog;
-    int tempfd, fd, cj, oldlineno;
+    int tempfd = -1, fd, cj, oldlineno;
     int oldshst, osubsh, oloops;
     FILE *obshin;
     char *old_scriptname = scriptname, *us;
diff -ru ../z.old/Src/parse.c Src/parse.c
--- ../z.old/Src/parse.c	Mon Mar 20 11:06:58 2000
+++ Src/parse.c	Mon Mar 20 11:14:52 2000
@@ -2596,7 +2596,7 @@
 {
     int dfd, hlen, tlen;
     LinkList progs, lnames;
-    Shfunc shf;
+    Shfunc shf = NULL;
 
     if (!strsfx(FD_EXT, dump))
 	dump = dyncat(dump, FD_EXT);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
@ 2000-03-16  8:46 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-16  8:46 UTC (permalink / raw)
  To: zsh-workers


Zefram wrote:

> Sven Wischnowsky wrote:
> >+		   (to = (long) i * M_ISIZE * (m_m[i] - m_f[i])), (cu += to));
> 
> This is undefined behaviour.  Order of evaluation of function arguments
> is unspecified, and there are no intervening sequence points.

Ouch... and I even know that. Sorry, and thanks.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
  2000-03-15 13:28 Sven Wischnowsky
@ 2000-03-16  1:35 ` Zefram
  0 siblings, 0 replies; 9+ messages in thread
From: Zefram @ 2000-03-16  1:35 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
>+		   (to = (long) i * M_ISIZE * (m_m[i] - m_f[i])), (cu += to));

This is undefined behaviour.  Order of evaluation of function arguments
is unspecified, and there are no intervening sequence points.

-zefram

diff -ru ../z.old/Src/mem.c Src/mem.c
--- ../z.old/Src/mem.c	Wed Mar 15 12:53:07 2000
+++ Src/mem.c	Wed Mar 15 14:26:18 2000
@@ -1247,10 +1247,12 @@
     }
     printf("\nsize\tmalloc\tfree\tdiff\ttotal\tcum\n");
     for (i = 0, cu = 0; i < 1024; i++)
-	if (m_m[i] || m_f[i])
+	if (m_m[i] || m_f[i]) {
+	    to = (long) i * M_ISIZE * (m_m[i] - m_f[i]);
 	    printf("%ld\t%d\t%d\t%d\t%ld\t%ld\n",
 		   (long)i * M_ISIZE, m_m[i], m_f[i], m_m[i] - m_f[i],
-		   (to = (long) i * M_ISIZE * (m_m[i] - m_f[i])), (cu += to));
+		   to, (cu += to));
+	}
 
     if (m_m[i] || m_f[i])
 	printf("big\t%d\t%d\t%d\n", m_m[i], m_f[i], m_m[i] - m_f[i]);
END


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
@ 2000-03-15 13:28 Sven Wischnowsky
  2000-03-16  1:35 ` Zefram
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-15 13:28 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> If I press tab in a position where all commands are completed, I get a
> very long delay.

And of course we should have a look why this is so slow...

It turned out that one of the main reasons was that permalloc()
(called from the function that does $compstate[nmatches]) got called
very often and re-calculated the list of matches again and again (of
course).

The patch below at least makes it re-use already calculated and
perm-alloc'ed groups again if they didn't change. This already makes
it more than twice as fast as it was before for me. It won't have much 
effect for people who don't use the group-name style, though. I played
a bit with re-using already perm-alloc'ed matches, but that had
surprisingly little effect, so I took it out again.


Has anyone ever had a look at the output of `mem' (with zsh's
allocation routines) after doing completion in command position with
an empty prefix? Very interesting. I get some 300KB of free (i.e.
unused) memory. Urgh.

Maybe we should make it calculate the amount of memory needed for each 
group (there wouldn't be much overhead for this, I think), allocate
only one big block and write everything in it. And then we could think 
about giving support for such relatively-short-lived-but-still-zalloc'ed
blocks in mem.c, allocating them out of the way of normal zalloc'ed
memory (e.g. using mmap() if available, like we do it for heaps).


The hunks in mem.c just add some more information a bit of information 
to the output of `mem' that I've been missing once too often now.

Bye
 Sven

diff -ru ../z.old/Src/Zle/comp.h Src/Zle/comp.h
--- ../z.old/Src/Zle/comp.h	Wed Mar 15 12:53:10 2000
+++ Src/Zle/comp.h	Wed Mar 15 13:49:04 2000
@@ -73,6 +73,8 @@
     int *widths;		/* column widths for listpacked */
     int totl;			/* total length */
     int shortest;		/* length of shortest match */
+    Cmgroup perm;		/* perm. alloced version of this group */
+    int new;			/* new matches since last permalloc() */
 };
 
 
diff -ru ../z.old/Src/Zle/compcore.c Src/Zle/compcore.c
--- ../z.old/Src/Zle/compcore.c	Wed Mar 15 12:53:10 2000
+++ Src/Zle/compcore.c	Wed Mar 15 13:53:45 2000
@@ -2174,6 +2174,7 @@
     addlinknode((alt ? fmatches : matches), cm);
 
     newmatches = 1;
+    mgroup->new = 1;
 
     if (!complastprompt || !*complastprompt)
 	dolastprompt = 0;
@@ -2262,6 +2263,8 @@
     mgroup->matches = NULL;
     mgroup->ylist = NULL;
     mgroup->expls = NULL;
+    mgroup->perm = NULL;
+    mgroup->new = 0;
 
     mgroup->lexpls = expls = newlinklist();
     mgroup->lmatches = matches = newlinklist();
@@ -2519,12 +2522,12 @@
 mod_export int
 permmatches(int last)
 {
-    Cmgroup g = amatches, n;
+    Cmgroup g = amatches, n, opm;
     Cmatch *p, *q;
     Cexpl *ep, *eq, e, o;
     LinkList mlist;
     static int fi = 0;
-    int nn, nl, ll, gn = 1, mn = 1, rn;
+    int nn, nl, ll, gn = 1, mn = 1, rn, ofi = fi;
 
     if (pmatches && !newmatches) {
 	if (last && fi)
@@ -2533,9 +2536,7 @@
     }
     newmatches = fi = 0;
 
-    if (pmatches)
-	freematches(pmatches);
-
+    opm = pmatches;
     pmatches = lmatches = NULL;
     nmatches = smatches = 0;
 
@@ -2545,68 +2546,87 @@
 	fi = 1;
     }
     while (g) {
-	if (fi)
-	    /* We have no matches, try ignoring fignore. */
-	    mlist = g->lfmatches;
-	else
-	    mlist = g->lmatches;
-
-	g->matches = makearray(mlist, 1, g->flags, &nn, &nl, &ll);
-	g->mcount = nn;
-	if ((g->lcount = nn - nl) < 0)
-	    g->lcount = 0;
-	g->llcount = ll;
-	if (g->ylist) {
-	    g->lcount = arrlen(g->ylist);
-	    smatches = 2;
-	}
-	g->expls = (Cexpl *) makearray(g->lexpls, 0, 0, &(g->ecount),
-				       NULL, NULL);
+	if (fi != ofi || !g->perm || g->new) {
+	    if (fi)
+		/* We have no matches, try ignoring fignore. */
+		mlist = g->lfmatches;
+	    else
+		mlist = g->lmatches;
+
+	    g->matches = makearray(mlist, 1, g->flags, &nn, &nl, &ll);
+	    g->mcount = nn;
+	    if ((g->lcount = nn - nl) < 0)
+		g->lcount = 0;
+	    g->llcount = ll;
+	    if (g->ylist) {
+		g->lcount = arrlen(g->ylist);
+		smatches = 2;
+	    }
+	    g->expls = (Cexpl *) makearray(g->lexpls, 0, 0, &(g->ecount),
+					   NULL, NULL);
 
-	g->ccount = 0;
+	    g->ccount = 0;
 
-	nmatches += g->mcount;
-	smatches += g->lcount;
+	    nmatches += g->mcount;
+	    smatches += g->lcount;
 
-	n = (Cmgroup) zcalloc(sizeof(struct cmgroup));
-
-	if (!lmatches)
-	    lmatches = n;
-	if (pmatches)
-	    pmatches->prev = n;
-	n->next = pmatches;
-	pmatches = n;
-	n->prev = 0;
-	n->num = gn++;
-
-	n->flags = g->flags;
-	n->mcount = g->mcount;
-	n->matches = p = (Cmatch *) zcalloc((n->mcount + 1) * sizeof(Cmatch));
-	n->name = ztrdup(g->name);
-	for (q = g->matches; *q; q++, p++)
-	    *p = dupmatch(*q, nbrbeg, nbrend);
-	*p = NULL;
-
-	n->lcount = g->lcount;
-	n->llcount = g->llcount;
-	if (g->ylist)
-	    n->ylist = zarrdup(g->ylist);
-	else
-	    n->ylist = NULL;
+	    n = (Cmgroup) zcalloc(sizeof(struct cmgroup));
 
-	if ((n->ecount = g->ecount)) {
-	    n->expls = ep = (Cexpl *) zcalloc((n->ecount + 1) * sizeof(Cexpl));
-	    for (eq = g->expls; (o = *eq); eq++, ep++) {
-		*ep = e = (Cexpl) zcalloc(sizeof(struct cexpl));
-		e->count = (fi ? o->fcount : o->count);
-		e->str = ztrdup(o->str);
+	    if (g->perm) {
+		g->perm->next = NULL;
+		freematches(g->perm);
 	    }
-	    *ep = NULL;
-	} else
-	    n->expls = NULL;
+	    g->perm = n;
 
-	n->widths = NULL;
+	    if (!lmatches)
+		lmatches = n;
+	    if (pmatches)
+		pmatches->prev = n;
+	    n->next = pmatches;
+	    pmatches = n;
+	    n->prev = NULL;
+	    n->num = gn++;
+	    n->flags = g->flags;
+	    n->mcount = g->mcount;
+	    n->matches = p = (Cmatch *) zcalloc((n->mcount + 1) * sizeof(Cmatch));
+	    n->name = ztrdup(g->name);
+	    for (q = g->matches; *q; q++, p++)
+		*p = dupmatch(*q, nbrbeg, nbrend);
+	    *p = NULL;
+
+	    n->lcount = g->lcount;
+	    n->llcount = g->llcount;
+	    if (g->ylist)
+		n->ylist = zarrdup(g->ylist);
+	    else
+		n->ylist = NULL;
+
+	    if ((n->ecount = g->ecount)) {
+		n->expls = ep = (Cexpl *) zcalloc((n->ecount + 1) * sizeof(Cexpl));
+		for (eq = g->expls; (o = *eq); eq++, ep++) {
+		    *ep = e = (Cexpl) zcalloc(sizeof(struct cexpl));
+		    e->count = (fi ? o->fcount : o->count);
+		    e->str = ztrdup(o->str);
+		}
+		*ep = NULL;
+	    } else
+		n->expls = NULL;
 
+	    n->widths = NULL;
+	} else {
+	    if (!lmatches)
+		lmatches = g->perm;
+	    if (pmatches)
+		pmatches->prev = g->perm;
+	    g->perm->next = pmatches;
+	    pmatches = g->perm;
+	    g->perm->prev = NULL;
+
+	    nmatches += g->mcount;
+	    smatches += g->lcount;
+	    g->num = gn++;
+	}
+	g->new = 0;
 	g = g->next;
     }
     for (g = pmatches; g; g = g->next) {
@@ -2664,7 +2684,7 @@
 
     while (g) {
 	n = g->next;
-	
+
 	for (m = g->matches; *m; m++)
 	    freematch(*m, g->nbrbeg, g->nbrend);
 
diff -ru ../z.old/Src/mem.c Src/mem.c
--- ../z.old/Src/mem.c	Wed Mar 15 12:53:07 2000
+++ Src/mem.c	Wed Mar 15 14:26:18 2000
@@ -1219,7 +1219,7 @@
     int i, ii, fi, ui, j;
     struct m_hdr *m, *mf, *ms;
     char *b, *c, buf[40];
-    long u = 0, f = 0;
+    long u = 0, f = 0, to, cu;
 
     if (ops['v']) {
 	printf("The lower and the upper addresses of the heap. Diff gives\n");
@@ -1242,13 +1242,15 @@
 	printf("values, i.e. the number of blocks of that size that is\n");
 	printf("currently allocated. Total is the product of size and diff,\n");
 	printf("i.e. the number of bytes that are allocated for blocks of\n");
-	printf("this size.\n");
+	printf("this size. The last field gives the accumulated number of\n");
+	printf("bytes for all sizes.\n");
     }
-    printf("\nsize\tmalloc\tfree\tdiff\ttotal\n");
-    for (i = 0; i < 1024; i++)
+    printf("\nsize\tmalloc\tfree\tdiff\ttotal\tcum\n");
+    for (i = 0, cu = 0; i < 1024; i++)
 	if (m_m[i] || m_f[i])
-	    printf("%ld\t%d\t%d\t%d\t%ld\n", (long)i * M_ISIZE, m_m[i], m_f[i],
-		   m_m[i] - m_f[i], (long)i * M_ISIZE * (m_m[i] - m_f[i]));
+	    printf("%ld\t%d\t%d\t%d\t%ld\t%ld\n",
+		   (long)i * M_ISIZE, m_m[i], m_f[i], m_m[i] - m_f[i],
+		   (to = (long) i * M_ISIZE * (m_m[i] - m_f[i])), (cu += to));
 
     if (m_m[i] || m_f[i])
 	printf("big\t%d\t%d\t%d\n", m_m[i], m_f[i], m_m[i] - m_f[i]);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
@ 2000-03-15  9:48 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-15  9:48 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Mar 14,  4:27pm, Sven Wischnowsky wrote:
> } Subject: Re: command completion taking ages
> }
> }   zstyle ':completion:*:*:-command-:*' tag-order 'maybe()' -
> } 
> }   maybe() { [[ -n $PREFIX ]] && comptry "$@" }
> 
> I wondered about that, but it's not a general solution for cases where
> there are multiple tags and you DO want to order them when there IS a
> non-empty prefix/suffix.  Is there some way for the function to say
> "I didn't generate any matches, but don't try any more tags even so"?

We can easily make it use the return value for this...

So, with this patch one can simplify the above to:

  maybe() { [[ -n $PREFIX ]] }


Bye
 Sven

diff -ru ../z.old/Completion/Core/_sort_tags Completion/Core/_sort_tags
--- ../z.old/Completion/Core/_sort_tags	Wed Mar 15 10:33:12 2000
+++ Completion/Core/_sort_tags	Wed Mar 15 10:44:18 2000
@@ -26,3 +26,5 @@
 esac
 
 comptry "$@"
+
+return 0
diff -ru ../z.old/Completion/Core/_tags Completion/Core/_tags
--- ../z.old/Completion/Core/_tags	Wed Mar 15 10:33:12 2000
+++ Completion/Core/_tags	Wed Mar 15 10:40:35 2000
@@ -44,7 +44,11 @@
     for tag in $order; do
       case $tag in
       -)     nodef=yes;;
-      *\(\)) "${${tag%%[ 	]#\(\)}##[ 	]#}" "$@";;
+      *\(\)) if ! "${${tag%%[ 	]#\(\)}##[ 	]#}" "$@"; then
+               nodef=yes
+               break
+             fi
+             ;;
       \!*)   comptry "${(@)argv:#(${(j:|:)~${=tag[2,-1]}})}";;
       ?*)    comptry ${=tag};;
       esac
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo	Wed Mar 15 10:32:51 2000
+++ Doc/Zsh/compsys.yo	Wed Mar 15 10:44:08 2000
@@ -1435,7 +1435,10 @@
 this case the function var(func) will be called which can then define
 in which order tags are to be used based on additional context
 information. See the tt(_sort_tags) function below for a description
-of how such functions can be implemented.
+of how such functions can be implemented. The return value of the
+function is used to decide if the following values for the style
+should be used. If it is zero, they are used and if it is non-zero,
+they are not used.
 
 If no style has been defined for a context, the strings tt(arguments
 values), tt(options), tt(globbed-files), tt(directories) and

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: command completion taking ages
@ 2000-03-13 12:23 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-03-13 12:23 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> If I press tab in a position where all commands are completed, I get a
> very long delay. This is quite annoying even though I can interrupt it
> with Ctrl-C. Is there a way using the zstyle, tags and _wanted stuff
> that I could indicate with zstyle that I don't want to complete commands
> if $#PREFIX = 0. I couldn't see any styles which are passed through eval
> in any of _requested, _wanted, _tags etc but other than using the
> high-level stuff for tag ordering, I don't fully understand the tag
> selection stuff so I may well have missed something.

No, we don't have something like that. I don't remember exactly when
it was, but I have been thinking about something like that too...

Maybe some style tested by _setup or _tags saying if a certain tag
should only be used under certain circumstances. Either using the
approach we (well, I, and it wasn't my best idea either) used for
_match, i.e. the value of the style is math-eval'ed and if non-zero,
the tag is used. Or -- probably better, and we should then think about
using it for _match, too -- the value is just eval'ed and if it has a
zero return status (or the style is not set), the tag is used.

(Hm, now that I think of it... it's quite easy, why haven't I...)

Any other opinions?


Back to your question: currently you can only 1) use tag-order to make 
it generate as few matches as possible, or 2) (probably better) copy
and modify _command_names to test [[ -z $PREFIX] (or (( $#PREFIX )) if 
you prefer).


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* command completion taking ages
@ 2000-03-12 15:44 Oliver Kiddle
  0 siblings, 0 replies; 9+ messages in thread
From: Oliver Kiddle @ 2000-03-12 15:44 UTC (permalink / raw)
  To: Zsh workers

If I press tab in a position where all commands are completed, I get a
very long delay. This is quite annoying even though I can interrupt it
with Ctrl-C. Is there a way using the zstyle, tags and _wanted stuff
that I could indicate with zstyle that I don't want to complete commands
if $#PREFIX = 0. I couldn't see any styles which are passed through eval
in any of _requested, _wanted, _tags etc but other than using the
high-level stuff for tag ordering, I don't fully understand the tag
selection stuff so I may well have missed something.

Oliver


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-03-20 10:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-14 15:27 command completion taking ages Sven Wischnowsky
2000-03-14 18:32 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2000-03-20 10:28 Sven Wischnowsky
2000-03-16  8:46 Sven Wischnowsky
2000-03-15 13:28 Sven Wischnowsky
2000-03-16  1:35 ` Zefram
2000-03-15  9:48 Sven Wischnowsky
2000-03-13 12:23 Sven Wischnowsky
2000-03-12 15:44 Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).