From: Sven Wischnowsky <wischnow@berkom.de>
To: zsh-workers@sunsite.dk
Subject: Re: aggregated options in completion lists
Date: Tue, 21 May 2002 10:02:53 +0200 [thread overview]
Message-ID: <15593.65325.907154.556245@wischnow.berkom.de> (raw)
In-Reply-To: <15584.50137.133265.722041@wischnow.berkom.de>
Hi
The calculation for max-match-length (still no better name) could
fail. We have to iterate here, as for completion lists.
Bye
Sven
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.79
diff -u -r1.79 computil.c
--- Src/Zle/computil.c 21 May 2002 07:39:42 -0000 1.79
+++ Src/Zle/computil.c 21 May 2002 08:00:46 -0000
@@ -46,6 +46,7 @@
int pre; /* longest prefix (before description) */
int suf; /* longest suffix (description) */
int maxg; /* size of largest group */
+ int maxglen; /* columns for matches of largest group */
int groups; /* number of groups */
int descs; /* number of non-group matches with desc */
int gpre; /* prefix length for group display */
@@ -118,12 +119,21 @@
/* Find matches with same descriptions and group them. */
static void
-cd_group()
+cd_group(int maxg)
{
Cdset set1, set2;
Cdstr str1, str2, *strp;
int num, len;
+ cd_state.groups = cd_state.descs = cd_state.maxglen = 0;
+ cd_state.maxg = 0;
+
+ for (set1 = cd_state.sets; set1; set1 = set1->next)
+ for (str1 = set1->strs; str1; str1 = str1->next) {
+ str1->kind = 0;
+ str1->other = NULL;
+ }
+
for (set1 = cd_state.sets; set1; set1 = set1->next) {
for (str1 = set1->strs; str1; str1 = str1->next) {
if (!str1->desc || str1->kind != 0)
@@ -131,6 +141,8 @@
num = 1;
len = str1->len + cd_state.slen;
+ if (len > cd_state.maxglen)
+ cd_state.maxglen = len;
strp = &(str1->other);
for (set2 = set1; set2; set2 = set2->next) {
@@ -138,8 +150,10 @@
str2; str2 = str2->next)
if (str2->desc && !strcmp(str1->desc, str2->desc)) {
len += 2 + str2->len;
- if (len > cd_state.maxmlen)
+ if (len > cd_state.maxmlen || num == maxg)
break;
+ if (len > cd_state.maxglen)
+ cd_state.maxglen = len;
str1->kind = 1;
str2->kind = 2;
num++;
@@ -151,11 +165,6 @@
}
*strp = NULL;
- if (len >= columns) {
- cd_state.groups = 0;
-
- return;
- }
if (num > 1)
cd_state.groups++;
else
@@ -200,7 +209,7 @@
return strcmp((*((Cdstr *) a))->str, (*((Cdstr *) b))->str);
}
-static void
+static int
cd_prep()
{
Cdrun run, *runp;
@@ -253,6 +262,13 @@
qsort(grps, lines, sizeof(Cdstr), cd_sort);
+ cd_state.gpre = 0;
+ for (i = 0; i < cd_state.maxg; i++)
+ cd_state.gpre += wids[i] + 2;
+
+ if (cd_state.gpre > cd_state.maxmlen && cd_state.maxglen > 1)
+ return 1;
+
expl = (Cdrun) zalloc(sizeof(*run));
expl->type = CRT_EXPL;
expl->strs = grps[0];
@@ -325,9 +341,6 @@
run->count = i;
}
}
- cd_state.gpre = 0;
- for (i = 0; i < cd_state.maxg; i++)
- cd_state.gpre += wids[i] + 2;
} else if (cd_state.showd) {
for (set = cd_state.sets; set; set = set->next) {
if (set->desc) {
@@ -370,6 +383,8 @@
}
}
*runp = NULL;
+
+ return 0;
}
/* Duplicate and concatenate two arrays. Return the result. */
@@ -495,12 +510,19 @@
if ((*args = tmp))
args++;
}
- if (disp && grp)
- cd_group();
+ if (disp && grp) {
+ int mg = columns;
- cd_calc();
- cd_prep();
+ do {
+ cd_group(mg);
+ mg = cd_state.maxg - 1;
+ cd_calc();
+ } while (cd_prep());
+ } else {
+ cd_calc();
+ cd_prep();
+ }
cd_parsed = 1;
return 0;
}
--
Sven Wischnowsky wischnow@berkom.de
next prev parent reply other threads:[~2002-05-21 8:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-12 14:10 Borsenkow Andrej
2002-05-13 9:11 ` Sven Wischnowsky
2002-05-14 7:59 ` Sven Wischnowsky
2002-05-21 8:02 ` Sven Wischnowsky [this message]
2002-05-21 8:50 ` Oliver Kiddle
2002-05-21 8:57 ` Borsenkow Andrej
2002-05-23 12:13 ` Sven Wischnowsky
2002-05-23 12:15 ` Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15593.65325.907154.556245@wischnow.berkom.de \
--to=wischnow@berkom.de \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).