1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-28 17:10:59 +01:00

35127#1: Fix _describe/compdescribe problem with unsorted groups

This commit is contained in:
Daniel Shahaf 2015-05-14 11:04:19 +00:00
parent 2f6a8a6c6c
commit 9fcc105ff6
3 changed files with 47 additions and 7 deletions

View file

@ -210,6 +210,25 @@ cd_calc()
}
}
/* Return 1 if cd_state specifies unsorted groups, 0 otherwise. */
static int
cd_groups_want_sorting(void)
{
Cdset set;
char *const *i;
for (set = cd_state.sets; set; set = set->next)
for (i = set->opts; *i; i++) {
if (!strncmp(*i, "-V", 2))
return 0;
else if (!strncmp(*i, "-J", 2))
return 1;
}
/* Sorted by default */
return 1;
}
static int
cd_sort(const void *a, const void *b)
{
@ -283,7 +302,8 @@ cd_prep()
unmetafy(s->sortstr, &dummy);
}
qsort(grps, preplines, sizeof(Cdstr), cd_sort);
if (cd_groups_want_sorting())
qsort(grps, preplines, sizeof(Cdstr), cd_sort);
for (i = preplines, strp = grps; i > 1; i--, strp++) {
strp2 = strp + 1;
@ -441,7 +461,17 @@ cd_arrcat(char **a, char **b)
}
}
/* Initialisation. Store and calculate the string and matches and so on. */
/* Initialisation. Store and calculate the string and matches and so on.
*
* nam: argv[0] of the builtin
* hide: ???
* mlen: see max-matches-width style
* sep: see list-seperator style
* opts: options to (eventually) pass to compadd.
* Returned via 2nd return parameter of 'compdescribe -g'.
* args: ??? (the positional arguments to 'compdescribe')
* disp: 1 if descriptions should be shown, 0 otherwise
*/
static int
cd_init(char *nam, char *hide, char *mlen, char *sep,
@ -699,8 +729,12 @@ cd_get(char **params)
dpys[0] = ztrdup(run->strs->str);
mats[1] = dpys[1] = NULL;
opts = cd_arrdup(run->strs->set->opts);
/* Set -2V, possibly reusing the group name from an existing -J/-V
* flag. */
for (dp = opts + 1; *dp; dp++)
if (dp[0][0] == '-' && dp[0][1] == 'J')
if ((dp[0][0] == '-' && dp[0][1] == 'J') ||
(dp[0][0] == '-' && dp[0][1] == 'V'))
break;
if (*dp) {
char *s = tricat("-2V", "", dp[0] + 2);