* aggregated options in completion lists @ 2002-05-12 14:10 Borsenkow Andrej 2002-05-13 9:11 ` Sven Wischnowsky 2002-05-14 7:59 ` Sven Wischnowsky 0 siblings, 2 replies; 8+ messages in thread From: Borsenkow Andrej @ 2002-05-12 14:10 UTC (permalink / raw) To: Zsh hackers list This looks strange. And of course all descriptions are cut off (I am sorry, actually every option is on a single line, it is just I do not know how to tell it Evolution). There probably should be some (settable) limit on column width. The listing is from rsync completion. -andrej --owner -- preserve owne --partial -- keep partiall --password-file -- get password --password-file --include-from --exclude-from --config -- specify: file --perms -- preserve perm --port -- specify alter --progress -- show progress ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 2002-05-12 14:10 aggregated options in completion lists Borsenkow Andrej @ 2002-05-13 9:11 ` Sven Wischnowsky 2002-05-14 7:59 ` Sven Wischnowsky 1 sibling, 0 replies; 8+ messages in thread From: Sven Wischnowsky @ 2002-05-13 9:11 UTC (permalink / raw) To: zsh-workers Borsenkow Andrej wrote: > This looks strange. And of course all descriptions are cut off (I am > sorry, actually every option is on a single line, it is just I do not > know how to tell it Evolution). There probably should be some (settable) > limit on column width. > > The listing is from rsync completion. > > -andrej > > --owner -- preserve owne Aha. This is what I mentioned when I wrote the columnisation stuff. Hmhm. I'll have a look. And there are probably more possible ways we can go now than I can think of. Bye Sven -- Sven Wischnowsky wischnow@berkom.de ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 2002-05-12 14:10 aggregated options in completion lists Borsenkow Andrej 2002-05-13 9:11 ` Sven Wischnowsky @ 2002-05-14 7:59 ` Sven Wischnowsky 2002-05-21 8:02 ` Sven Wischnowsky 1 sibling, 1 reply; 8+ messages in thread From: Sven Wischnowsky @ 2002-05-14 7:59 UTC (permalink / raw) To: zsh-workers Borsenkow Andrej wrote: > This looks strange. And of course all descriptions are cut off (I am > sorry, actually every option is on a single line, it is just I do not > know how to tell it Evolution). There probably should be some (settable) > limit on column width. Below is a patch. This is the simple implementation. One could thing about how nice it were if the code could do: % foo <TAB> description --long-option1 --long-option2 --long-option3 -- description I.e., to not repeat the description for every sub-set of matches it creates. That, however is much harder to implement and, if uses often, could probably be slightly irritating, I think. Opinions? Can anyone help me with a better name for that style? `max-match-length' just doesn't sound right. `max-match-columns' might be better, but sound (to me) as if the number of matches per line were meant, which it isn't. I'll commit it anyway. Bye Sven Index: Completion/Base/Utility/_describe =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_describe,v retrieving revision 1.11 diff -u -r1.11 _describe --- Completion/Base/Utility/_describe 6 May 2002 07:59:50 -0000 1.11 +++ Completion/Base/Utility/_describe 14 May 2002 07:57:50 -0000 @@ -2,7 +2,7 @@ # This can be used to add options or values with descriptions as matches. -local _opt _expl _tmpm _tmpd +local _opt _expl _tmpm _tmpd _mlen local _type=values _descr _ret=1 _showd _nm _hide _args _grp _sep local csl="$compstate[list]" csl2 local _oargv _argv _new _strs _mats _opts _i _try=0 @@ -25,6 +25,8 @@ zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes zstyle -s ":completion:${curcontext}:$_type" list-separator _sep || _sep=-- +zstyle -s ":completion:${curcontext}:$_type" max-match-length _mlen || + _mlen=$((COLUMNS/2)) _descr="$1" shift @@ -97,9 +99,9 @@ fi if [[ -n "$_showd" ]]; then - compdescribe -I "$_hide" "$_sep " _expl "$_grp[@]" "$@" + compdescribe -I "$_hide" "$_mlen" "$_sep " _expl "$_grp[@]" "$@" else - compdescribe -i "$_hide" "$@" + compdescribe -i "$_hide" "$_mlen" "$@" fi compstate[list]="$csl" Index: Completion/Zsh/Command/_zstyle =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v retrieving revision 1.9 diff -u -r1.9 _zstyle --- Completion/Zsh/Command/_zstyle 16 Apr 2002 07:48:46 -0000 1.9 +++ Completion/Zsh/Command/_zstyle 14 May 2002 07:57:51 -0000 @@ -80,6 +80,7 @@ matcher c: matcher-list c: max-errors c: + max-match-length c:max-match-length menu c:boolauto muttrc c:_files numbers c:bool @@ -380,6 +381,10 @@ separator) _message -e separators 'separator string' + ;; + + max-match-length) + _message -e numbers 'maximum display length for matches' ;; urgh) Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.155 diff -u -r1.155 compsys.yo --- Doc/Zsh/compsys.yo 14 May 2002 07:54:24 -0000 1.155 +++ Doc/Zsh/compsys.yo 14 May 2002 07:57:51 -0000 @@ -1766,6 +1766,20 @@ The default value for this style is `tt(2 numeric)'. ) +kindex(max-match-length, completion style) +item(tt(max-match-length))( +This is used to define the maximum length to use for the matches when +listing matches with descriptions. In such lists, matches with the +same description will be grouped together, but that means that in +cases where many matches have the same description, the matches take +up most of the display width, leaving only little room for the +descriptions. By setting this style one can specify whether one +prefers to make more matches be grouped together or whether the shell +should try keep more of the descriptions visible. + +The value should give the maximum number of display columns to give to +the matches, the default is half the screen width. +) kindex(menu, completion style) item(tt(menu))( If this is set to true in a given context, using any of the tags defined Index: Src/Zle/computil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v retrieving revision 1.77 diff -u -r1.77 computil.c --- Src/Zle/computil.c 17 Apr 2002 07:28:19 -0000 1.77 +++ Src/Zle/computil.c 14 May 2002 07:57:52 -0000 @@ -41,6 +41,7 @@ int showd; /* != 0 if descriptions should be shown */ char *sep; /* the separator string */ int slen; /* its length */ + int maxmlen; /* maximum length to allow for the matches */ Cdset sets; /* the sets of matches */ int pre; /* longest prefix (before description) */ int suf; /* longest suffix (description) */ @@ -129,22 +130,26 @@ continue; num = 1; - len = str1->len; + len = str1->len + cd_state.slen; strp = &(str1->other); - for (set2 = set1; set2; set2 = set2->next) + for (set2 = set1; set2; set2 = set2->next) { for (str2 = (set2 == set1 ? str1->next : set2->strs); str2; str2 = str2->next) if (str2->desc && !strcmp(str1->desc, str2->desc)) { + len += 2 + str2->len; + if (len > cd_state.maxmlen) + break; str1->kind = 1; str2->kind = 2; num++; - len += str2->len; *strp = str2; strp = &(str2->other); } + if (str2) + break; + } *strp = NULL; - len += num * 2 + cd_state.slen; if (len >= columns) { cd_state.groups = 0; @@ -393,12 +398,13 @@ /* Initialisation. Store and calculate the string and matches and so on. */ static int -cd_init(char *nam, char *hide, char *sep, char **opts, char **args, int disp) +cd_init(char *nam, char *hide, char *mlen, char *sep, + char **opts, char **args, int disp) { Cdset *setp, set; Cdstr *strp, str; char **ap, *tmp; - int grp = 0; + int grp = 0, itmp; if (cd_parsed) { zsfree(cd_state.sep); @@ -411,7 +417,12 @@ cd_state.sets = NULL; cd_state.showd = disp; cd_state.maxg = cd_state.groups = cd_state.descs = 0; - + cd_state.maxmlen = atoi(mlen); + itmp = columns - cd_state.slen - 4; + if (cd_state.maxmlen > itmp) + cd_state.maxmlen = itmp; + if (cd_state.maxmlen < 4) + cd_state.maxmlen = 4; if (*args && !strcmp(*args, "-g")) { args++; grp = 1; @@ -537,7 +548,7 @@ /* We are building a columnised list with dummy matches * but there are also matches without descriptions. * Those end up in a different group, so make sure that - * groupd doesn't have an explanation. */ + * group doesn't have an explanation. */ for (mp = dp = opts; *mp; mp++) { if (dp[0][0] == '-' && dp[0][1] == 'X') { @@ -679,25 +690,25 @@ } switch (args[0][1]) { case 'i': - if (n < 2) { + if (n < 3) { zwarnnam(nam, "not enough arguments", NULL, 0); return 1; } - return cd_init(nam, args[1], "", NULL, args + 2, 0); + return cd_init(nam, args[1], args[2], "", NULL, args + 3, 0); case 'I': - if (n < 5) { + if (n < 6) { zwarnnam(nam, "not enough arguments", NULL, 0); return 1; } else { char **opts; - if (!(opts = getaparam(args[3]))) { - zwarnnam(nam, "unknown parameter: %s", args[2], 0); + if (!(opts = getaparam(args[4]))) { + zwarnnam(nam, "unknown parameter: %s", args[4], 0); return 1; } - return cd_init(nam, args[1], args[2], opts, args + 4, 1); + return cd_init(nam, args[1], args[2], args[3], opts, args + 5, 1); } case 'g': if (cd_parsed) { -- Sven Wischnowsky wischnow@berkom.de ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 2002-05-14 7:59 ` Sven Wischnowsky @ 2002-05-21 8:02 ` Sven Wischnowsky 2002-05-21 8:50 ` Oliver Kiddle 0 siblings, 1 reply; 8+ messages in thread From: Sven Wischnowsky @ 2002-05-21 8:02 UTC (permalink / raw) To: zsh-workers 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 2002-05-21 8:02 ` Sven Wischnowsky @ 2002-05-21 8:50 ` Oliver Kiddle 2002-05-21 8:57 ` Borsenkow Andrej ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Oliver Kiddle @ 2002-05-21 8:50 UTC (permalink / raw) To: Sven Wischnowsky; +Cc: zsh-workers On Tue, May 21, 2002 at 10:02:53AM +0200, Sven Wischnowsky wrote: > > The calculation for max-match-length (still no better name) could How about max-matches-width? Or maybe max-width-matches. On Tue, May 14, 2002 at 09:59:21AM +0200, Sven Wischnowsky wrote: > > Below is a patch. This is the simple implementation. One could thing > about how nice it were if the code could do: > > % foo <TAB> > description > --long-option1 --long-option2 > --long-option3 -- description > > I.e., to not repeat the description for every sub-set of matches it > creates. That, however is much harder to implement and, if uses often, > could probably be slightly irritating, I think. > > Opinions? It would be better. Another possibility would be to vary the position of the description from one line to the next which would be good in situations such as where only a couple out of many options have multiple options for the same description. Handling of empty descriptions is perhaps not ideal. I'm getting lines like: % info -d ~/info zsh <tab> menu item Arithmetic Evaluation -- Command Execution -- Oliver This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 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 2 siblings, 0 replies; 8+ messages in thread From: Borsenkow Andrej @ 2002-05-21 8:57 UTC (permalink / raw) To: Oliver Kiddle; +Cc: Sven Wischnowsky, zsh-workers On Tue, 21 May 2002, Oliver Kiddle wrote: > > Handling of empty descriptions is perhaps not ideal. I'm getting > lines like: > % info -d ~/info zsh <tab> > menu item > Arithmetic Evaluation -- > Command Execution -- > It is a bug in _info. I have new version that does not add empty descriptions but I am off for this week so I commit it later. -andrej ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 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 2 siblings, 0 replies; 8+ messages in thread From: Sven Wischnowsky @ 2002-05-23 12:13 UTC (permalink / raw) To: zsh-workers Oliver Kiddle wrote: > ... > > > Below is a patch. This is the simple implementation. One could thing > > about how nice it were if the code could do: > > > > % foo <TAB> > > description > > --long-option1 --long-option2 > > --long-option3 -- description > > > > I.e., to not repeat the description for every sub-set of matches it > > creates. That, however is much harder to implement and, if uses often, > > could probably be slightly irritating, I think. > > > > Opinions? > > It would be better. Ok, here is the patch. > Another possibility would be to vary the position of the description > from one line to the next which would be good in situations such as > where only a couple out of many options have multiple options for the > same description. I'm not too sure I'd like that and anyway we'd have to find good thresholds. Dunno. Bye Sven Index: Src/Zle/computil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v retrieving revision 1.80 diff -u -r1.80 computil.c --- Src/Zle/computil.c 21 May 2002 08:04:35 -0000 1.80 +++ Src/Zle/computil.c 23 May 2002 12:13:01 -0000 @@ -260,8 +260,6 @@ *strp++ = gs; } - 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; @@ -269,6 +267,23 @@ if (cd_state.gpre > cd_state.maxmlen && cd_state.maxglen > 1) return 1; + qsort(grps, lines, sizeof(Cdstr), cd_sort); + + for (i = lines, strp = grps; i > 1; i--, strp++) { + strp2 = strp + 1; + if (!strcmp((*strp)->desc, (*strp2)->desc)) + continue; + for (j = i - 2, strp2++; j > 0; j--, strp2++) + if (!strcmp((*strp)->desc, (*strp2)->desc)) { + Cdstr tmp = *strp2; + + memmove(strp + 2, strp + 1, + (strp2 - strp - 1) * sizeof(Cdstr)); + + *++strp = tmp; + i--; + } + } expl = (Cdrun) zalloc(sizeof(*run)); expl->type = CRT_EXPL; expl->strs = grps[0]; @@ -666,6 +681,10 @@ dpys = (char **) zalloc((i + 1) * sizeof(char *)); for (dp = dpys, str = run->strs; str; str = str->run) { + if (str->run && !strcmp(str->desc, str->run->desc)) { + *dp++ = ztrdup(""); + continue; + } memset(dbuf + cd_state.slen, ' ', dlen - 1); dbuf[dlen + cd_state.slen - 1] = '\0'; strcpy(dbuf, cd_state.sep); -- Sven Wischnowsky wischnow@berkom.de ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: aggregated options in completion lists 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 2 siblings, 0 replies; 8+ messages in thread From: Sven Wischnowsky @ 2002-05-23 12:15 UTC (permalink / raw) To: zsh-workers Oliver Kiddle wrote: > On Tue, May 21, 2002 at 10:02:53AM +0200, Sven Wischnowsky wrote: > > > > The calculation for max-match-length (still no better name) could > > How about max-matches-width? Or maybe max-width-matches. I've taken the former. Thanks. Bye Sven Index: Completion/Base/Utility/_describe =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_describe,v retrieving revision 1.12 diff -u -r1.12 _describe --- Completion/Base/Utility/_describe 14 May 2002 08:01:18 -0000 1.12 +++ Completion/Base/Utility/_describe 23 May 2002 12:15:29 -0000 @@ -25,7 +25,7 @@ zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes zstyle -s ":completion:${curcontext}:$_type" list-separator _sep || _sep=-- -zstyle -s ":completion:${curcontext}:$_type" max-match-length _mlen || +zstyle -s ":completion:${curcontext}:$_type" max-matches-width _mlen || _mlen=$((COLUMNS/2)) _descr="$1" Index: Completion/Zsh/Command/_zstyle =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v retrieving revision 1.10 diff -u -r1.10 _zstyle --- Completion/Zsh/Command/_zstyle 14 May 2002 08:01:18 -0000 1.10 +++ Completion/Zsh/Command/_zstyle 23 May 2002 12:15:29 -0000 @@ -80,7 +80,7 @@ matcher c: matcher-list c: max-errors c: - max-match-length c:max-match-length + max-matches-width c:max-matches-width menu c:boolauto muttrc c:_files numbers c:bool @@ -383,8 +383,8 @@ _message -e separators 'separator string' ;; - max-match-length) - _message -e numbers 'maximum display length for matches' + max-matches-width) + _message -e numbers 'maximum display width for matches' ;; urgh) Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.156 diff -u -r1.156 compsys.yo --- Doc/Zsh/compsys.yo 14 May 2002 08:01:18 -0000 1.156 +++ Doc/Zsh/compsys.yo 23 May 2002 12:15:30 -0000 @@ -1766,9 +1766,9 @@ The default value for this style is `tt(2 numeric)'. ) -kindex(max-match-length, completion style) -item(tt(max-match-length))( -This is used to define the maximum length to use for the matches when +kindex(max-matches-width, completion style) +item(tt(max-matches-width))( +This is used to define the maximum width to use for the matches when listing matches with descriptions. In such lists, matches with the same description will be grouped together, but that means that in cases where many matches have the same description, the matches take -- Sven Wischnowsky wischnow@berkom.de ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2002-05-23 12:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-05-12 14:10 aggregated options in completion lists Borsenkow Andrej 2002-05-13 9:11 ` Sven Wischnowsky 2002-05-14 7:59 ` Sven Wischnowsky 2002-05-21 8:02 ` Sven Wischnowsky 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
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).