summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Base/Utility/_describe8
-rw-r--r--Completion/Zsh/Command/_zstyle5
-rw-r--r--Doc/Zsh/compsys.yo14
-rw-r--r--Src/Zle/computil.c39
5 files changed, 55 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 11b941078..dc6987c0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2002-05-14 Sven Wischnowsky <wischnow@zsh.org>
+ * 17147: Completion/Base/Utility/_describe,
+ Completion/Zsh/Command/_zstyle, Doc/Zsh/compsys.yo,
+ Src/Zle/computil.c: allow users to give the maximum number of
+ display-columns the matches should take up via the style
+ currently named max-match-length
+
* 17146: Doc/Zsh/compsys.yo: fix doc for _describe, mention -t
option
diff --git a/Completion/Base/Utility/_describe b/Completion/Base/Utility/_describe
index b215b6279..0a291302b 100644
--- a/Completion/Base/Utility/_describe
+++ b/Completion/Base/Utility/_describe
@@ -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 @@ fi
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 @@ while _tags; do
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"
diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index 99ee8f72b..db4d6604b 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -80,6 +80,7 @@ styles=(
matcher c:
matcher-list c:
max-errors c:
+ max-match-length c:max-match-length
menu c:boolauto
muttrc c:_files
numbers c:bool
@@ -382,6 +383,10 @@ while (( $#state )); do
_message -e separators 'separator string'
;;
+ max-match-length)
+ _message -e numbers 'maximum display length for matches'
+ ;;
+
urgh)
_wanted values expl no compadd no false off 0
;;
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 200f83532..ad43e19ab 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1766,6 +1766,20 @@ performed.
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
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index a426a9a5b..f6c9b54e9 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -41,6 +41,7 @@ struct cdstate {
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 @@ cd_group()
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 @@ cd_arrcat(char **a, char **b)
/* 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_init(char *nam, char *hide, char *sep, char **opts, char **args, int disp)
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 @@ cd_get(char **params)
/* 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 @@ bin_compdescribe(char *nam, char **args, char *ops, int func)
}
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) {