* long/short options @ 2001-07-12 16:01 Andrej Borsenkow 2001-07-13 8:07 ` Sven Wischnowsky 0 siblings, 1 reply; 10+ messages in thread From: Andrej Borsenkow @ 2001-07-12 16:01 UTC (permalink / raw) To: ZSH Workers Mailing List mount under Cygwin is simple, but every option has a long and short form. Using exclusions I can prevent both to be on command line, but listing looks somewhat ugly: (tty1)% mount -s --binary Completing Windows path Completing option --binary -- Unix line endings LF --cygwin-executable -- all files under mountpoint are cygwin executables --executable -- all files under mountpoint are executables --force -- be silent --text -- (default) DOS line endings CR-LF -X -- all files under mountpoint are cygwin executables -b -- Unix line endings LF -f -- be silent -t -- (default) DOS line endings CR-LF -x -- all files under mountpoint are executables What I'd really like is something like -b, --binary -- Unix line endings ... Or do I miss something and this is already possible? Another question is, in case of '(-c -i --import-old-mounts -p --show-cygdrive-prefix)--change-cygdrive- prefix[cygdrive prefix]:cygdrive prefix (POSIX path):_files -/' I get something like (tty1)% mount --change-cygdrive-prefix -- No matches for: `cygdrive prefix (POSIX path)' or `file' ^^^^^^^^^ How can I prevent the last part (I want description only from option). Oh, and is _files /*(/) the right way to complete absolute pathnames? :-) -andrej ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: long/short options 2001-07-12 16:01 long/short options Andrej Borsenkow @ 2001-07-13 8:07 ` Sven Wischnowsky 2001-07-13 17:01 ` Bart Schaefer 0 siblings, 1 reply; 10+ messages in thread From: Sven Wischnowsky @ 2001-07-13 8:07 UTC (permalink / raw) To: zsh-workers Andrej Borsenkow wrote: > ... > > What I'd really like is something like > > -b, --binary -- Unix line endings > ... > > Or do I miss something and this is already possible? It isn't. And it's hard to write (but that didn't stop us in the past). One would have to change the way comparguments stores and reports the options and one would have to change the code in _describe to list things differently. And one would have to handle this correctly with menu selection where users expect a one-to-one correspondence between matches (in this case: lines) and strings to insert in the line. That's more work than I want to invest in it. > Another question is, in case of > > '(-c -i --import-old-mounts -p --show-cygdrive-prefix)--change-cygdrive- > prefix[cygdrive prefix]:cygdrive prefix (POSIX path):_files -/' > > I get something like > > (tty1)% mount --change-cygdrive-prefix -- > No matches for: `cygdrive prefix (POSIX path)' or `file' > ^^^^^^^^^ > How can I prevent the last part (I want description only from option). I was about to tell you that you can't because it is added by _files in line 75 which we need for the tag handling. But then I looked again and maybe the patch is all we need. It makes _files check if there is a user-supplied description and if so, doesn't use `file' as its own description (it then uses an empty string which is basically ignored in _description). This is a development version. Let's try. > Oh, and is _files /*(/) the right way to complete absolute pathnames? :-) The other hunk below is for this one. Somehow I thought `_files -P/ -W "(/)" -/' would be the best solution. But _path_files had some problems with a -P-prefix if it was already on the line and there isn't much we can do about that -- 60% of _path_files is about prefix and suffix handling. But the patch below duplicates code in the C-code to make _path_files ignore a -P-prefix on the line. And with that the call to _files as shown above seems to work. Bye Sven Index: Completion/Unix/Type/_files =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_files,v retrieving revision 1.3 diff -u -r1.3 _files --- Completion/Unix/Type/_files 2001/05/07 09:25:05 1.3 +++ Completion/Unix/Type/_files 2001/07/13 07:28:33 @@ -65,7 +65,11 @@ if [[ "$sdef" = *:${tag}:* ]]; then descr="${(Q)sdef#*:${tag}:}" else - descr=file + if (( $opts[(I)-X] )); then + descr= + else + descr=file + fi end=yes fi Index: Completion/Unix/Type/_path_files =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v retrieving revision 1.7 diff -u -r1.7 _path_files --- Completion/Unix/Type/_path_files 2001/07/06 10:46:31 1.7 +++ Completion/Unix/Type/_path_files 2001/07/13 07:28:33 @@ -5,7 +5,7 @@ local linepath realpath donepath prepath testpath exppath skips skipped local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre -local pats haspats ignore pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx +local pats haspats ignore pfx pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx local nm=$compstate[nmatches] menu matcher mopts sort match mid accex fake typeset -U prepaths exppaths @@ -15,7 +15,7 @@ # Get the options. zparseopts -a mopts \ - 'P:=pfxsfx' 'S:=pfxsfx' 'q=pfxsfx' 'r:=pfxsfx' 'R:=pfxsfx' \ + 'P:=pfx' 'S:=pfxsfx' 'q=pfxsfx' 'r:=pfxsfx' 'R:=pfxsfx' \ 'W:=prepaths' 'F:=ignore' 'M+:=matcher' \ J+: V+: X+: 1: 2: n: 'f=tmp1' '/=tmp1' 'g+:-=tmp1' @@ -28,6 +28,10 @@ pats=( "${(@)=${(@M)tmp1:#-g*}#-g}" ) fi pats=( "${(@)pats:# #}" ) + +if (( $#pfx )); then + compset -P "$pfx[2]" || pfxsfx=( "$pfx[@]" "$pfxsfx[@]" ) +fi if (( $#prepaths )); then tmp1="${prepaths[2]}" -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: long/short options 2001-07-13 8:07 ` Sven Wischnowsky @ 2001-07-13 17:01 ` Bart Schaefer 2001-07-16 7:14 ` Sven Wischnowsky 0 siblings, 1 reply; 10+ messages in thread From: Bart Schaefer @ 2001-07-13 17:01 UTC (permalink / raw) To: Sven Wischnowsky, zsh-workers On Jul 13, 10:07am, Sven Wischnowsky wrote: } Subject: Re: long/short options } } Andrej Borsenkow wrote: } } > ... } > } > What I'd really like is something like } > } > -b, --binary -- Unix line endings } > ... } > } > Or do I miss something and this is already possible? } } It isn't. And it's hard to write (but that didn't stop us in the past). } One would have to change the way comparguments stores and reports the } options and one would have to change the code in _describe to list } things differently. I would thing that the real reason it's difficult is because of menu- selection. If the options get lumped together like that, where should the select-cursor go, and what should it insert on the command line? You'd have to decide that e.g. its not possible to menu-select the one- letter version of the option, or some such. Anyway, that aside, obviously it would require a change to _describe, but would it really need a change in the C code? Taking this fragment as an example: _arguments -s \ '(-b -t --text)--binary[Unix line endings LF]' \ '(--binary -t --text)-b[Unix line endings LF]' One solution would be to have _describe actually scan the description strings looking for duplicates, and condense them in the listing by adding one option to the display string for the other and dropping the duplicate from the list of completions (i.e., the duplicate would get passed to `compadd -n ...'). That would have the effect I mentioned, that you'd see `-b, --binary ...' but only be able to menu-select `--binary'. That still means the caller of _arguments has to supply all the duplicate description strings for _describe to search for. So another possibility would be for the caller to use something like: _arguments -s \ '(-b -t --text)--binary[Unix line endings LF]' \ '(--binary -t --text)-b[(--binary)]' Here _describe would parse off the leading parenthesized string from the description. If the option named in the parens is among the possible completions, it prepends the option name and a comma to the description string of the option named in the parens and uses `compadd -n' for the option that has this special description. Otherwise it adds the option and the rest of the description (after the parens) as usual. [This is to handle a strange special case where you have two options that mean the same thing individually but have different exclusion lists, e.g. one of them has a new meaning when in combination with some third option.] Both of these approaches mean that _describe has to make an extra pass over the options before `compadd'ing them. And I'm really not sure how difficult they actually would be to implement. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: long/short options 2001-07-13 17:01 ` Bart Schaefer @ 2001-07-16 7:14 ` Sven Wischnowsky 2001-07-18 13:07 ` PATCH: " Sven Wischnowsky 0 siblings, 1 reply; 10+ messages in thread From: Sven Wischnowsky @ 2001-07-16 7:14 UTC (permalink / raw) To: zsh-workers Bart Schaefer wrote: > ... > > Anyway, that aside, obviously it would require a change to _describe, > but would it really need a change in the C code? Well, ok, it doesn't, but it might be easier to write because it's the C-code that builds the strings to display. > Taking this fragment > as an example: > > _arguments -s \ > '(-b -t --text)--binary[Unix line endings LF]' \ > '(--binary -t --text)-b[Unix line endings LF]' > > One solution would be to have _describe actually scan the description > strings looking for duplicates, and condense them in the listing by > adding one option to the display string for the other and dropping the > duplicate from the list of completions (i.e., the duplicate would get > passed to `compadd -n ...'). That would have the effect I mentioned, > that you'd see `-b, --binary ...' but only be able to menu-select > `--binary'. Strings added with -n are intentionally made visible in menu selection, by the way. > That still means the caller of _arguments has to supply all the duplicate > description strings for _describe to search for. So another possibility > would be for the caller to use something like: > > _arguments -s \ > '(-b -t --text)--binary[Unix line endings LF]' \ > '(--binary -t --text)-b[(--binary)]' > > Here _describe would parse off the leading parenthesized string from the > description. If the option named in the parens is among the possible > completions, it prepends the option name and a comma to the description > string of the option named in the parens and uses `compadd -n' for the > option that has this special description. Otherwise it adds the option > and the rest of the description (after the parens) as usual. [This is > to handle a strange special case where you have two options that mean > the same thing individually but have different exclusion lists, e.g. one > of them has a new meaning when in combination with some third option.] Hm, the first way above would be easier for users because they could uses brace expansions as I suggested to Andrej some time ago. > Both of these approaches mean that _describe has to make an extra pass > over the options before `compadd'ing them. And I'm really not sure how > difficult they actually would be to implement. Now that you've done the thinking -- not too hard, actually. I would still put it in the C-code because that has to separate the strings from the descriptions and look at them closely anyway (and searching for duplicate descriptions should be much faster there). Hm we could then add a style to _describe so that users can select if they want 1) matches with the same description put on one line or not and 2) if they want them to appear as two matches in menu selection or if the shorter or longer one should just be ignored. Although 2) may go too far because _describe has no information about things like option- arguments or exclusion lists that may be different. Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 10+ messages in thread
* PATCH: Re: long/short options 2001-07-16 7:14 ` Sven Wischnowsky @ 2001-07-18 13:07 ` Sven Wischnowsky 2001-07-18 13:46 ` Andrej Borsenkow 2001-07-18 17:20 ` Oliver Kiddle 0 siblings, 2 replies; 10+ messages in thread From: Sven Wischnowsky @ 2001-07-18 13:07 UTC (permalink / raw) To: zsh-workers I just had to play a bit today... This makes _describe and compdescribe try to group matches with the same description. I've used Bart's first suggestion, i.e. it really searches for matches with the same desription, not with some special description syntax, although that would be quite easy to add or change now. But I preferred it this way, because it makes adding multiple options with equal arguments easier using brace expansion. The whole thing can be turned off by using the new list-grouped style. It defaults to `true', because it can make completion lists shorter, which is always a good thing. I've also made sure that in menu selection the entries for all options belonging together are shown together. Unfortunately that meant to make all those strings start with the same (the list of options), which is a bit ugly. If you try it, you'll see that I at least changed the descriptions of the second to n'th string to be `|' which sorts in after most normal characters and hence makes the list look not too stupid. I'm open to every suggestion to make this even more pleasing -- the best we could get is probably to make the second to n'th entry show only the i'th option and something like ` - " - ', but for that we would have to sort the strings and add them as an unsorted group (i.e. mess with the compadd-options _describe gets from its caller). Certainly doable, though. The hunks in compresult and complist make sure that matches with a line-display string (compadd -ld) can be hidden with the `-n' option which didn't work before and which we need to make the strings appear only in menu selection. It also changes complist to not treat duplicate and `hidden' matches specially (in terms of colouring) unless the `du' and `hi' capabilities are set by the user. And one last remark: some completion functions seem to make sure to not add multiple options with the same description (try `ls', for an example). That was probably sensible before, but now it should be changed. I haven't done anything about that yet, maybe we should all try to look out for such things. The patch actually looks larger than it is -- quite a bit of re-indentation and I've changed the internals of compdescribe almost completely, making it much cleaner and easier to extend. I'm now considering if it might be sensible to make it cache the last list it built, but so far I haven't found anything that really got slower. Bye Sven Index: Completion/Base/Utility/_describe =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_describe,v retrieving revision 1.1 diff -u -r1.1 _describe --- Completion/Base/Utility/_describe 2001/04/02 11:10:44 1.1 +++ Completion/Base/Utility/_describe 2001/07/18 12:56:08 @@ -2,8 +2,8 @@ # This can be used to add options or values with descriptions as matches. -local _opt _expl _tmps _tmpd _tmpmd _tmpms _ret=1 _showd _nm _hide _args -local _type=values _descr +local _opt _expl _tmps _tmpd _tmph _tmpmd _tmpms _tmpmh +local _type=values _descr _ret=1 _showd _nm _hide _args _grp # Get the option. @@ -21,6 +21,11 @@ # Do the tests. `showd' is set if the descriptions should be shown. zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes +if zstyle -T ":completion:${curcontext}:$_type" list-grouped; then + _grp=(-g) +else + _grp=() +fi _descr="$1" shift @@ -33,12 +38,12 @@ while _next_label "$_type" _expl "$_descr"; do if [[ -n "$_showd" ]]; then - compdescribe -I ' -- ' "$@" + compdescribe -I ' -- ' "$_grp[@]" "$@" else compdescribe -i "$@" fi - while compdescribe -g _args _tmpd _tmpmd _tmps _tmpms; do + while compdescribe -g _args _tmpd _tmpmd _tmph _tmpmh _tmps _tmpms; do # See if we should remove the option prefix characters. @@ -53,6 +58,7 @@ fi compadd "$_args[@]" "$_expl[@]" -ld _tmpd -a _tmpmd && _ret=0 + compadd -n "$_args[@]" "$_expl[@]" -ld _tmph -a _tmpmh && _ret=0 compadd "$_args[@]" "$_expl[@]" -d _tmps -a _tmpms && _ret=0 done done Index: Completion/Zsh/Command/_zstyle =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v retrieving revision 1.2 diff -u -r1.2 _zstyle --- Completion/Zsh/Command/_zstyle 2001/07/17 09:04:29 1.2 +++ Completion/Zsh/Command/_zstyle 2001/07/18 12:56:08 @@ -55,6 +55,7 @@ last-prompt c:bool list c:listwhen list-colors c: + list-grouped c:bool list-packed c:bool list-prompt c: list-rows-first c:bool Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.129 diff -u -r1.129 compsys.yo --- Doc/Zsh/compsys.yo 2001/07/17 09:04:29 1.129 +++ Doc/Zsh/compsys.yo 2001/07/18 12:56:11 @@ -1508,6 +1508,17 @@ The default colors are the same as for the GNU tt(ls) command and can be obtained by setting the style to an empty string (i.e. tt('')). ) +kindex(list-grouped, completion style) +item(tt(list-grouped))( +If this style is `true' (the default), the completion system will try to +make some completion listings more compact by grouping matches together. +For example, options for commands that have the same description (which +are shown because the tt(verbose) style is set to `true') will have only +one entry in the list, showing all options that can be used to select +the specific behaviour. When menu selection is done on such a list, the +matches will appear as separate entries in the list to be able to select +each of them. +) kindex(list-packed, completion style) item(tt(list-packed))( Like the tt(list-colors) style, this is tested with the tt(default) @@ -3462,6 +3473,9 @@ the tt(prefix-hidden), tt(prefix-needed) and tt(verbose) styles to find out if the strings should be added at all and if the descriptions should be shown. Without the `tt(-o)' option, only the tt(verbose) style is used. + +If selected by the tt(list-grouped) style, strings with the same +description will be added in a way that they appear together in the list. tt(_describe) uses the tt(_all_labels) function to generate the matches, so it does not need to appear inside a loop over tag labels. Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.42 diff -u -r1.42 complist.c --- Src/Zle/complist.c 2001/06/13 14:03:44 1.42 +++ Src/Zle/complist.c 2001/07/18 12:56:12 @@ -77,7 +77,7 @@ static char *defcols[] = { "0", "0", "1;31", "1;36", "33", "1;35", "1;33", "1;33", "1;32", NULL, - "\033[", "m", NULL, "0", "0", "7", "0", "0" + "\033[", "m", NULL, "0", "0", "7", NULL, NULL }; /* This describes a terminal string for a file type. */ @@ -444,6 +444,7 @@ return; } + zlrputs(c, "0"); } /* Turn off colouring. */ @@ -1170,7 +1171,8 @@ p = g->matches; for (; (m = *p); p++) { - if (m->disp && (m->flags & CMF_DISPLINE)) { + if (m->disp && (m->flags & CMF_DISPLINE) && + (showall || !(m->flags & (CMF_HIDE|CMF_NOLIST)))) { if (pnl) { if (dolistnl(ml) && compprintnl(ml)) goto end; @@ -1412,9 +1414,11 @@ mgtabp = mgtab + mm; mmlen = mcols; zcputs(&mcolors, g->name, COL_MA); - } else if (m->flags & CMF_NOLIST) + } else if ((m->flags & CMF_NOLIST) && + mcolors.files[COL_HI] && mcolors.files[COL_HI]->col) zcputs(&mcolors, g->name, COL_HI); - else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT))) + else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)) && + mcolors.files[COL_DU] && mcolors.files[COL_DU]->col) zcputs(&mcolors, g->name, COL_DU); else subcols = putmatchcol(&mcolors, g->name, m->disp); Index: Src/Zle/compresult.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v retrieving revision 1.37 diff -u -r1.37 compresult.c --- Src/Zle/compresult.c 2001/05/28 11:42:00 1.37 +++ Src/Zle/compresult.c 2001/07/18 12:56:12 @@ -1443,44 +1443,46 @@ } m->flags &= ~CMF_HIDE; - if (m->disp) { - if (m->flags & CMF_DISPLINE) { - nlines += 1 + printfmt(m->disp, 0, 0, 0); - g->flags |= CGF_HASDL; - } else { - l = niceztrlen(m->disp); - ndisp++; - if (l > glong) - glong = l; - if (l < gshort) - gshort = l; - totl += l; - mlens[m->gnum] = l; - } - nlist++; - if (!(m->flags & CMF_PACKED)) - g->flags &= ~CGF_PACKED; - if (!(m->flags & CMF_ROWS)) - g->flags &= ~CGF_ROWS; - } else if (showall || !(m->flags & (CMF_NOLIST | CMF_MULT))) { + if (showall || !(m->flags & (CMF_NOLIST | CMF_MULT))) { if ((m->flags & (CMF_NOLIST | CMF_MULT)) && (!m->str || !*m->str)) { m->flags |= CMF_HIDE; continue; } - l = niceztrlen(m->str); - ndisp++; - if (l > glong) - glong = l; - if (l < gshort) - gshort = l; - totl += l; - mlens[m->gnum] = l; - nlist++; - if (!(m->flags & CMF_PACKED)) - g->flags &= ~CGF_PACKED; - if (!(m->flags & CMF_ROWS)) - g->flags &= ~CGF_ROWS; + if (m->disp) { + if (m->flags & CMF_DISPLINE) { + nlines += 1 + printfmt(m->disp, 0, 0, 0); + g->flags |= CGF_HASDL; + } else { + l = niceztrlen(m->disp); + ndisp++; + if (l > glong) + glong = l; + if (l < gshort) + gshort = l; + totl += l; + mlens[m->gnum] = l; + } + nlist++; + if (!(m->flags & CMF_PACKED)) + g->flags &= ~CGF_PACKED; + if (!(m->flags & CMF_ROWS)) + g->flags &= ~CGF_ROWS; + } else { + l = niceztrlen(m->str); + ndisp++; + if (l > glong) + glong = l; + if (l < gshort) + gshort = l; + totl += l; + mlens[m->gnum] = l; + nlist++; + if (!(m->flags & CMF_PACKED)) + g->flags &= ~CGF_PACKED; + if (!(m->flags & CMF_ROWS)) + g->flags &= ~CGF_ROWS; + } } else hidden = 1; } @@ -1972,7 +1974,8 @@ if (g->flags & CGF_HASDL) { for (p = g->matches; (m = *p); p++) - if (m->disp && (m->flags & CMF_DISPLINE)) { + if (m->disp && (m->flags & CMF_DISPLINE) && + (showall || !(m->flags & (CMF_HIDE|CMF_NOLIST)))) { if (pnl) { putc('\n', shout); pnl = 0; Index: Src/Zle/computil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v retrieving revision 1.62 diff -u -r1.62 computil.c --- Src/Zle/computil.c 2001/06/26 09:05:10 1.62 +++ Src/Zle/computil.c 2001/07/18 12:56:14 @@ -31,59 +31,42 @@ #include "computil.pro" -/* Help for `_display'. */ +/* Help for `_describe'. */ -/* Calculation state. */ - -typedef struct cdisp *Cdisp; - -struct cdisp { - int pre; /* prefix length */ - int suf; /* suffix length */ - int colon; /* number of strings with descriptions */ -}; - -/* Calculate longest prefix and suffix and count the strings with - * descriptions. */ - -static void -cdisp_calc(Cdisp disp, char **args) -{ - char *cp; - int i, nbc; - - for (; *args; args++) { - for (nbc = 0, cp = *args; *cp && *cp != ':'; cp++) - if (*cp == '\\' && cp[1]) - cp++, nbc++; - if (*cp == ':' && cp[1]) { - disp->colon++; - if ((i = cp - *args - nbc) > disp->pre) - disp->pre = i; - if ((i = strlen(cp + 1)) > disp->suf) - disp->suf = i; - } - } -} - -/* Help fuer `_describe'. */ - typedef struct cdset *Cdset; +typedef struct cdstr *Cdstr; struct cdstate { int showd; /* != 0 if descriptions should be shown */ char *sep; /* the separator string */ + int slen; /* its length */ Cdset sets; /* the sets of matches */ - struct cdisp disp; /* used to calculate the alignment */ + int pre; /* longest prefix (before description) */ + int suf; /* longest suffix (description) */ +}; + +struct cdstr { + Cdstr next; /* the next one in this set */ + char *str; /* the string to display */ + char *desc; /* the description or NULL */ + char *match; /* the match to add */ + Cdstr other; /* next string with the same description */ + int kind; /* 0: not in a group, 1: the first, 2: other */ }; struct cdset { Cdset next; /* guess what */ char **opts; /* the compadd-options */ - char **strs; /* the display-strings */ - char **matches; /* the matches (or NULL) */ + Cdstr strs; /* the strings/matches */ + int count; /* number of matches in this set */ + int desc; /* number of matches with description */ }; +/* Maximum string length when used with descriptions. */ + +#define CD_MAXLEN 20 + + static struct cdstate cd_state; static int cd_parsed = 0; @@ -91,26 +74,116 @@ freecdsets(Cdset p) { Cdset n; + Cdstr s, sn; for (; p; p = n) { n = p->next; if (p->opts) freearray(p->opts); - if (p->strs) - freearray(p->strs); - if (p->matches) - freearray(p->matches); + for (s = p->strs; s; s = sn) { + sn = s->next; + zsfree(s->str); + zsfree(s->desc); + if (s->match != s->str) + zsfree(s->match); + zfree(s, sizeof(*s)); + } zfree(p, sizeof(*p)); } } +/* Find matches with same descriptions and group them. */ + +static void +cd_group() +{ + Cdset set1, set2; + Cdstr str1, str2, *strp; + int yep = 0; + char *buf; + + for (set1 = cd_state.sets; set1; set1 = set1->next) { + for (str1 = set1->strs; str1; str1 = str1->next) { + if (!str1->desc || str1->kind != 0) + continue; + + strp = &(str1->other); + + 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)) { + str1->kind = 1; + str2->kind = 2; + zsfree(str2->desc); + str2->desc = ztrdup("|"); + *strp = str2; + strp = &(str2->other); + yep = 1; + } + *strp = NULL; + } + } + if (!yep) + return; + + for (set1 = cd_state.sets; set1; set1 = set1->next) { + for (str1 = set1->strs; str1; str1 = str1->next) { + if (str1->kind != 1) + continue; + + buf = str1->str; + for (str2 = str1->other; str2; str2 = str2->other) + buf = zhtricat(buf, ", ", str2->str); + + for (str2 = str1; str2; str2 = str2->other) { + if (str2->str == str2->match) + str2->match = ztrdup(str2->match); + zsfree(str2->str); + str2->str = ztrdup(buf); + } + } + } +} + +/* Calculate longest prefix and suffix and count the strings with + * descriptions. */ + +static void +cd_calc() +{ + Cdset set; + Cdstr str; + int l; + + cd_state.pre = cd_state.suf = 0; + + for (set = cd_state.sets; set; set = set->next) { + set->count = set->desc = 0; + for (str = set->strs; str; str = str->next) { + set->count++; + if ((l = strlen(str->str)) > cd_state.pre) + cd_state.pre = l; + if (str->desc) { + set->desc++; + if ((l = strlen(str->desc)) > cd_state.suf) + cd_state.suf = l; + } + } + } + if (cd_state.pre > 20) + cd_state.pre = 20; +} + /* Initialisation. Store and calculate the string and matches and so on. */ static int cd_init(char *nam, char *sep, char **args, int disp) { Cdset *setp, set; + Cdstr *strp, str; char **ap, *tmp; + int grp = 0; if (cd_parsed) { zsfree(cd_state.sep); @@ -119,29 +192,57 @@ } setp = &(cd_state.sets); cd_state.sep = ztrdup(sep); + cd_state.slen = ztrlen(sep); cd_state.sets = NULL; - cd_state.disp.pre = cd_state.disp.suf = cd_state.disp.colon = 0; cd_state.showd = disp; + if (*args && !strcmp(*args, "-g")) { + args++; + grp = 1; + } while (*args) { *setp = set = (Cdset) zcalloc(sizeof(*set)); setp = &(set->next); + *setp = NULL; + set->opts = NULL; + set->strs = NULL; if (!(ap = get_user_var(*args))) { zwarnnam(nam, "invalid argument: %s", *args, 0); + zsfree(cd_state.sep); + freecdsets(cd_state.sets); return 1; } - set->strs = zarrdup(ap); - - if (disp) - cdisp_calc(&(cd_state.disp), set->strs); + for (strp = &(set->strs); *ap; ap++) { + *strp = str = (Cdstr) zalloc(sizeof(*str)); + strp = &(str->next); + + str->kind = 0; + str->other = NULL; + + for (tmp = *ap; *tmp && *tmp != ':'; tmp++) + if (*tmp == '\\' && tmp[1]) + tmp++; + + if (*tmp) + str->desc = ztrdup(rembslash(tmp + 1)); + else + str->desc = NULL; + *tmp = '\0'; + str->str = str->match = ztrdup(rembslash(*ap)); + } + str->next = NULL; if (*++args && **args != '-') { if (!(ap = get_user_var(*args))) { zwarnnam(nam, "invalid argument: %s", *args, 0); + zsfree(cd_state.sep); + freecdsets(cd_state.sets); return 1; } - set->matches = zarrdup(ap); + for (str = set->strs; str && *ap; str = str->next, ap++) + str->match = ztrdup(*ap); + args++; } for (ap = args; *args && @@ -154,6 +255,11 @@ if ((*args = tmp)) args++; } + if (disp && grp) + cd_group(); + + cd_calc(); + cd_parsed = 1; return 0; } @@ -166,77 +272,60 @@ Cdset set; if ((set = cd_state.sets)) { - char **sd, **sdp, **md, **mdp, **ss, **ssp, **ms, **msp; - char **p, **mp, *cp, *copy, *cpp, oldc; - int dl = 1, sl = 1, sepl = strlen(cd_state.sep); - int pre = cd_state.disp.pre, suf = cd_state.disp.suf; - VARARR(char, buf, pre + suf + sepl + 1); - - for (p = set->strs; *p; p++) - if (cd_state.showd) { - for (cp = *p; *cp && *cp != ':'; cp++) - if (*cp == '\\' && cp[1]) - cp++; - if (*cp == ':' && cp[1]) - dl++; - else - sl++; - } else - sl++; - - sd = (char **) zalloc(dl * sizeof(char *)); - ss = (char **) zalloc(sl * sizeof(char *)); - md = (char **) zalloc(dl * sizeof(char *)); - ms = (char **) zalloc(sl * sizeof(char *)); - - if (cd_state.showd) { - memcpy(buf + pre, cd_state.sep, sepl); - suf = pre + sepl; - } - - /* Build the aligned display strings. */ - - for (sdp = sd, ssp = ss, mdp = md, msp = ms, - p = set->strs, mp = set->matches; *p; p++) { - copy = dupstring(*p); - for (cp = cpp = copy; *cp && *cp != ':'; cp++) { - if (*cp == '\\' && cp[1]) - cp++; - *cpp++ = *cp; - } - oldc = *cpp; - *cpp = '\0'; - if (((cpp == cp && oldc == ':') || *cp == ':') && cp[1] && - cd_state.showd) { - memset(buf, ' ', pre); - memcpy(buf, copy, (cpp - copy)); - strcpy(buf + suf, cp + 1); - *sdp++ = ztrdup(buf); - if (mp) { - *mdp++ = ztrdup(*mp); - if (*mp) - mp++; - } else - *mdp++ = ztrdup(copy); - } else { - *ssp++ = ztrdup(copy); - if (mp) { - *msp++ = ztrdup(*mp); - if (*mp) - mp++; - } else - *msp++ = ztrdup(copy); - } - } - *sdp = *ssp = *mdp = *msp = NULL; - - p = zarrdup(set->opts); + char **sd, **sdp, **md, **mdp, **sh, **shp, **mh, **mhp; + char **ss, **ssp, **ms, **msp; + Cdstr str; + VARARR(char, buf, cd_state.pre + cd_state.suf + cd_state.slen + 1); + char *sufp = NULL, *disp; + + if (cd_state.showd) { + memcpy(buf + cd_state.pre, cd_state.sep, cd_state.slen); + sufp = buf + cd_state.pre + cd_state.slen; + } + sd = (char **) zalloc((set->desc + 1) * sizeof(char *)); + md = (char **) zalloc((set->desc + 1) * sizeof(char *)); + sh = (char **) zalloc((set->desc + 1) * sizeof(char *)); + mh = (char **) zalloc((set->desc + 1) * sizeof(char *)); + ss = (char **) zalloc((set->count + 1) * sizeof(char *)); + ms = (char **) zalloc((set->count + 1) * sizeof(char *)); + + for (sdp = sd, mdp = md, shp = sh, mhp = mh, + ssp = ss, msp = ms, str = set->strs; + str; + str = str->next) { + if (cd_state.showd && str->desc) { + if (strlen(str->str) > CD_MAXLEN) + disp = tricat(str->str, cd_state.sep, str->desc); + else { + strcpy(sufp, str->desc); + memset(buf, ' ', cd_state.pre); + memcpy(buf, str->str, strlen(str->str)); + disp = ztrdup(buf); + } + if (strlen(disp) >= columns) + disp[columns - 1] = '\0'; + + if (str->kind == 2) { + *shp++ = disp; + *mhp++ = ztrdup(str->match); + } else { + *sdp++ = disp; + *mdp++ = ztrdup(str->match); + } + } else { + *ssp++ = ztrdup(str->str); + *msp++ = ztrdup(str->match); + } + } + *sdp = *mdp = *shp = *mhp = *ssp = *msp = NULL; - setaparam(params[0], p); + setaparam(params[0], zarrdup(set->opts)); setaparam(params[1], sd); setaparam(params[2], md); - setaparam(params[3], ss); - setaparam(params[4], ms); + setaparam(params[3], sh); + setaparam(params[4], mh); + setaparam(params[5], ss); + setaparam(params[6], ms); cd_state.sets = set->next; set->next = NULL; @@ -268,8 +357,8 @@ if (cd_parsed) { int n = arrlen(args); - if (n != 6) { - zwarnnam(nam, (n < 6 ? "not enough arguments" : + if (n != 8) { + zwarnnam(nam, (n < 8 ? "not enough arguments" : "too many arguments"), NULL, 0); return 1; } -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: PATCH: Re: long/short options 2001-07-18 13:07 ` PATCH: " Sven Wischnowsky @ 2001-07-18 13:46 ` Andrej Borsenkow 2001-07-18 13:51 ` Sven Wischnowsky 2001-07-18 17:20 ` Oliver Kiddle 1 sibling, 1 reply; 10+ messages in thread From: Andrej Borsenkow @ 2001-07-18 13:46 UTC (permalink / raw) To: Sven Wischnowsky, zsh-workers bor@itsrm2% zsh bor@itsrm2% gdiff -bTAB zsh: bus error (core dumped) zsh bor@itsrm2% dbx V2.4C00 SINIX (Jun 19 2000) Copyright (C) Siemens AG 1998 Base: BSD, Copyright (C) The Regents of the University of California All rights reserved reading symbolic information ... Current signal in memory image is: SIGBUS (10) (non-existent physical address, f aulting address = 0x00000000) needed shared libraries: /tools/lib/zsh/4.1.0-dev-1/zsh/computil.so /tools/lib/zsh/4.1.0-dev-1/zsh/parameter.so /tools/lib/zsh/4.1.0-dev-1/zsh/zutil.so /tools/lib/zsh/4.1.0-dev-1/zsh/complist.so /tools/lib/zsh/4.1.0-dev-1/zsh/complete.so /tools/lib/zsh/4.1.0-dev-1/zsh/zle.so /usr/lib/libc.so.1 /lib/libnsl.so /lib/libdl.so /lib/libsocket.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/computil.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/parameter.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/zutil.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/complist.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/complete.so ... reading /tools/lib/zsh/4.1.0-dev-1/zsh/zle.so ... reading /usr/lib/libc.so.1 ... reading /lib/libnsl.so ... reading /lib/libdl.so ... reading /lib/libsocket.so [using memory image in core] 32bit dbx - 32bit program Type 'help' for help (dbx32) where cd_init(nam = "compdescribe", sep = " -- ", args = 0x82e084, disp = 1), line 234 in "/tools/src/zsh/Src/Zle/computil.c" bin_compdescribe(nam = "compdescribe", args = 0x82e060, ops = "", func = 0), lin e 355 in "/tools/src/zsh/Src/Zle/computil.c" $b189, line 367 in "/tools/src/zsh/Src/builtin.c" execbuiltin(args = 0x82df20, bn = 0xd1d7d90), line 367 in "/tools/src/zsh/Src/bu iltin.c" $b519, line 2294 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffe628c, input = 0, output = 0, how = 18, last1 = 2), line 22 94 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe628c, pcode = 2691, how = 18, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe628c, slcode = 7170, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe628c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe628c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe628c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe628c, pcode = 2627, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe628c, slcode = 24578, how = 2, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe628c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execwhile(state = 0x7ffe628c, do_exec = 0), line 398 in "/tools/src/zsh/Src/loop .c" execcmd(state = 0x7ffe628c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe628c, pcode = 2499, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe628c, slcode = 157698, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe628c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execwhile(state = 0x7ffe628c, do_exec = 0), line 398 in "/tools/src/zsh/Src/loop .c" execcmd(state = 0x7ffe628c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe628c, pcode = 2435, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe628c, slcode = 177154, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe628c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x81f9a0, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffe672c, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffe672c, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe672c, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe672c, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe672c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7b8b70, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7b8b70, wrap = (nilv), name = "_describe"), line 3459 in "/to ols/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7b8b70, w = (nilv), name = "_describe"), line 1249 in "/to ols/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7b8b70, wrap = 0xc62f2bc, name = "_describe"), line 3447 in " /tools/src/zsh/Src/exec.c" doshfunc(name = "_describe", prog = 0x7b8b70, doshargs = 0x82d830, flags = 8704, noreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7b1760, args = 0x82d830), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 228 3 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 24003, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 13314, how = 2, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe893c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 22531, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 174082, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe893c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 22339, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 235522, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe893c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 21443, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 327682, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execwhile(state = 0x7ffe893c, do_exec = 0), line 398 in "/tools/src/zsh/Src/loop .c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 14787, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 837634, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execwhile(state = 0x7ffe893c, do_exec = 0), line 398 in "/tools/src/zsh/Src/loop .c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 14723, how = 2, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 982018, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe893c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe893c, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe893c, pcode = 12419, how = 18, input = 0, output = 0, l ast1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe893c, slcode = 1267714, how = 18, last1 = 0), line 982 i n "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe893c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7e7b00, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffe8ddc, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffe8ddc, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe8ddc, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe8ddc, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe8ddc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7b0820, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7b0820, wrap = (nilv), name = "_arguments"), line 3459 in "/t ools/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7b0820, w = (nilv), name = "_arguments"), line 1249 in "/t ools/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7b0820, wrap = 0xc62f2bc, name = "_arguments"), line 3447 in "/tools/src/zsh/Src/exec.c" doshfunc(name = "_arguments", prog = 0x7b0820, doshargs = 0x7acd70, flags = 8704 , noreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7af5e0, args = 0x7acd70), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffe990c, input = 0, output = 0, how = 18, last1 = 2), line 22 83 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe990c, pcode = 3331, how = 18, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe990c, slcode = 80898, how = 18, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe990c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffe990c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffe990c, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe990c, pcode = 1219, how = 18, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe990c, slcode = 145410, how = 18, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe990c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7e7a70, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffe9dac, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffe9dac, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffe9dac, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffe9dac, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffe9dac, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7b8d50, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7b8d50, wrap = (nilv), name = "_diff_options"), line 3459 in "/tools/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7b8d50, w = (nilv), name = "_diff_options"), line 1249 in "/tools/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7b8d50, wrap = 0xc62f2bc, name = "_diff_options"), line 3447 in "/tools/src/zsh/Src/exec.c" doshfunc(name = "_diff_options", prog = 0x7b8d50, doshargs = 0x7ac2d0, flags = 8 704, noreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7b18a0, args = 0x7ac2d0), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffea43c, input = 0, output = 0, how = 18, last1 = 2), line 22 83 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffea43c, pcode = 259, how = 18, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffea43c, slcode = 6146, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffea43c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7e79b0, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffea8dc, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffea8dc, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffea8dc, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffea8dc, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffea8dc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7b8cf0, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7b8cf0, wrap = (nilv), name = "_diff"), line 3459 in "/tools/ src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7b8cf0, w = (nilv), name = "_diff"), line 1249 in "/tools/ src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7b8cf0, wrap = 0xc62f2bc, name = "_diff"), line 3447 in "/too ls/src/zsh/Src/exec.c" doshfunc(name = "_diff", prog = 0x7b8cf0, doshargs = 0x7ac280, flags = 8704, nor eturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7b1860, args = 0x7ac280), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffeb40c, input = 0, output = 0, how = 2, last1 = 2), line 228 3 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffeb40c, pcode = 5763, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffeb40c, slcode = 3106, how = 2, last1 = 0), line 982 in "/ tools/src/zsh/Src/exec.c" execlist(state = 0x7ffeb40c, dont_change_job = 1, exiting = 0), line 833 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffeb40c, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffeb40c, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffeb40c, pcode = 5635, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffeb40c, slcode = 56322, how = 2, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffeb40c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7971f0, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffeb8ac, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffeb8ac, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffeb8ac, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffeb8ac, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffeb8ac, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7d0c30, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7d0c30, wrap = (nilv), name = "_normal"), line 3459 in "/tool s/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7d0c30, w = (nilv), name = "_normal"), line 1249 in "/tool s/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7d0c30, wrap = 0xc62f2bc, name = "_normal"), line 3447 in "/t ools/src/zsh/Src/exec.c" doshfunc(name = "_normal", prog = 0x7d0c30, doshargs = 0x7ab898, flags = 8704, n oreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7bad80, args = 0x7ab898), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffec3dc, input = 0, output = 0, how = 2, last1 = 2), line 228 3 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffec3dc, pcode = 7555, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffec3dc, slcode = 4130, how = 2, last1 = 0), line 982 in "/ tools/src/zsh/Src/exec.c" execlist(state = 0x7ffec3dc, dont_change_job = 1, exiting = 0), line 833 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffec3dc, do_exec = 0), line 503 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffec3dc, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffec3dc, pcode = 7427, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffec3dc, slcode = 113666, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffec3dc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x797160, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffec87c, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffec87c, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffec87c, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffec87c, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffec87c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7b1060, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7b1060, wrap = (nilv), name = "_complete"), line 3459 in "/to ols/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7b1060, w = (nilv), name = "_complete"), line 1249 in "/to ols/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7b1060, wrap = 0xc62f2bc, name = "_complete"), line 3447 in " /tools/src/zsh/Src/exec.c" doshfunc(name = "_complete", prog = 0x7b1060, doshargs = 0x7ab478, flags = 8704, noreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" execshfunc(shf = 0x7b1300, args = 0x7ab478), line 3200 in "/tools/src/zsh/Src/ex ec.c" $b520, line 2283 in "/tools/src/zsh/Src/exec.c" $b519, line 2283 in "/tools/src/zsh/Src/exec.c" execcmd(state = 0x7ffedddc, input = 0, output = 0, how = 18, last1 = 2), line 22 83 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffedddc, pcode = 9987, how = 18, input = 0, output = 0, la st1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffedddc, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffedddc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execif(state = 0x7ffedddc, do_exec = 0), line 488 in "/tools/src/zsh/Src/loop.c" execcmd(state = 0x7ffedddc, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffedddc, pcode = 9667, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffedddc, slcode = 48130, how = 2, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffedddc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execfor(state = 0x7ffedddc, do_exec = 0), line 159 in "/tools/src/zsh/Src/loop.c " execcmd(state = 0x7ffedddc, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffedddc, pcode = 9155, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffedddc, slcode = 90114, how = 2, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffedddc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execfor(state = 0x7ffedddc, do_exec = 0), line 159 in "/tools/src/zsh/Src/loop.c " execcmd(state = 0x7ffedddc, input = 0, output = 0, how = 2, last1 = 2), line 224 1 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffedddc, pcode = 7875, how = 2, input = 0, output = 0, las t1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffedddc, slcode = 205826, how = 2, last1 = 0), line 982 in "/tools/src/zsh/Src/exec.c" execlist(state = 0x7ffedddc, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x796f80, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" execautofn(state = 0x7ffee27c, do_exec = 0), line 3228 in "/tools/src/zsh/Src/ex ec.c" execcmd(state = 0x7ffee27c, input = 0, output = 0, how = 18, last1 = 2), line 22 41 in "/tools/src/zsh/Src/exec.c" execpline2(state = 0x7ffee27c, pcode = 3, how = 18, input = 0, output = 0, last1 = 0), line 1192 in "/tools/src/zsh/Src/exec.c" execpline(state = 0x7ffee27c, slcode = 3074, how = 18, last1 = 0), line 982 in " /tools/src/zsh/Src/exec.c" execlist(state = 0x7ffee27c, dont_change_job = 1, exiting = 0), line 826 in "/to ols/src/zsh/Src/exec.c" execode(p = 0x7d03c0, dont_change_job = 1, exiting = 0), line 729 in "/tools/src /zsh/Src/exec.c" runshfunc(prog = 0x7d03c0, wrap = (nilv), name = "_main_complete"), line 3459 in "/tools/src/zsh/Src/exec.c" $b626, line 1249 in "/tools/src/zsh/Src/Zle/complete.c" comp_wrapper(prog = 0x7d03c0, w = (nilv), name = "_main_complete"), line 1249 in "/tools/src/zsh/Src/Zle/complete.c" runshfunc(prog = 0x7d03c0, wrap = 0xc62f2bc, name = "_main_complete"), line 3447 in "/tools/src/zsh/Src/exec.c" doshfunc(name = "_main_complete", prog = 0x7d03c0, doshargs = (nilv), flags = 0, noreturnval = 0), line 3390 in "/tools/src/zsh/Src/exec.c" $b653, line 774 in "/tools/src/zsh/Src/Zle/compcore.c" $b652, line 774 in "/tools/src/zsh/Src/Zle/compcore.c" $b629, line 774 in "/tools/src/zsh/Src/Zle/compcore.c" callcompfunc(s = "-b", fn = "_main_complete"), line 774 in "/tools/src/zsh/Src/Z le/compcore.c" $b656, line 924 in "/tools/src/zsh/Src/Zle/compcore.c" makecomplist(s = "-b", incmd = 0, lst = 0), line 924 in "/tools/src/zsh/Src/Zle/ compcore.c" do_completion(dummy = 0xc346dbc, dat = 0x7ffee784), line 342 in "/tools/src/zsh/ Src/Zle/compcore.c" runhookdef(h = 0xc346dbc, d = 0x7ffee784), line 1858 in "/tools/src/zsh/Src/modu le.c" docompletion(s = "-b", lst = 0, incmd = 0), line 1783 in "/tools/src/zsh/Src/Zle /zle_tricky.c" docomplete(lst = 0), line 803 in "/tools/src/zsh/Src/Zle/zle_tricky.c" $b848, line 205 in "/tools/src/zsh/Src/Zle/zle_tricky.c" completeword(args = 0xc346d04), line 205 in "/tools/src/zsh/Src/Zle/zle_tricky.c " completecall(args = 0xc346d04), line 181 in "/tools/src/zsh/Src/Zle/zle_tricky.c " $b904, line 662 in "/tools/src/zsh/Src/Zle/zle_main.c" $b902, line 662 in "/tools/src/zsh/Src/Zle/zle_main.c" execzlefunc(func = 0xc342948, args = 0xc346d04), line 662 in "/tools/src/zsh/Src /Zle/zle_main.c" zleread(lp = "%B%n@%m%#%b ", rp = (nilv), flags = 3), line 574 in "/tools/src/zs h/Src/Zle/zle_main.c" inputline(), line 265 in "/tools/src/zsh/Src/input.c" ingetc(), line 210 in "/tools/src/zsh/Src/input.c" ihgetc(), line 236 in "/tools/src/zsh/Src/hist.c" gettok(), line 631 in "/tools/src/zsh/Src/lex.c" yylex(), line 347 in "/tools/src/zsh/Src/lex.c" parse_event(), line 436 in "/tools/src/zsh/Src/parse.c" .init.loop(toplevel = 1, justonce = 0), line 123 in "/tools/src/zsh/Src/init.c" zsh_main(argc = 1, argv = 0x7ffeede4), line 1209 in "/tools/src/zsh/Src/init.c" .main.main(argc = 1, argv = 0x7ffeede4), line 37 in "/tools/src/zsh/Src/main.c" __start() at 0x40a144 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: PATCH: Re: long/short options 2001-07-18 13:46 ` Andrej Borsenkow @ 2001-07-18 13:51 ` Sven Wischnowsky 2001-07-18 13:59 ` Andrej Borsenkow 0 siblings, 1 reply; 10+ messages in thread From: Sven Wischnowsky @ 2001-07-18 13:51 UTC (permalink / raw) To: zsh-workers Andrej Borsenkow wrote: > bor@itsrm2% zsh > bor@itsrm2% gdiff -bTAB > zsh: bus error (core dumped) zsh Ouch. Sets without matches are possible. Sorry. Thanks. Bye Sven Index: Src/Zle/computil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v retrieving revision 1.63 diff -u -r1.63 computil.c --- Src/Zle/computil.c 2001/07/18 13:10:10 1.63 +++ Src/Zle/computil.c 2001/07/18 13:50:04 @@ -213,7 +213,7 @@ freecdsets(cd_state.sets); return 1; } - for (strp = &(set->strs); *ap; ap++) { + for (str = NULL, strp = &(set->strs); *ap; ap++) { *strp = str = (Cdstr) zalloc(sizeof(*str)); strp = &(str->next); @@ -231,7 +231,8 @@ *tmp = '\0'; str->str = str->match = ztrdup(rembslash(*ap)); } - str->next = NULL; + if (str) + str->next = NULL; if (*++args && **args != '-') { if (!(ap = get_user_var(*args))) { -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: PATCH: Re: long/short options 2001-07-18 13:51 ` Sven Wischnowsky @ 2001-07-18 13:59 ` Andrej Borsenkow 0 siblings, 0 replies; 10+ messages in thread From: Andrej Borsenkow @ 2001-07-18 13:59 UTC (permalink / raw) To: zsh-workers > > Ouch. Sets without matches are possible. > Looks like a canditate for regression test :-) -andrej ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: PATCH: Re: long/short options 2001-07-18 13:07 ` PATCH: " Sven Wischnowsky 2001-07-18 13:46 ` Andrej Borsenkow @ 2001-07-18 17:20 ` Oliver Kiddle 2001-07-19 8:36 ` Sven Wischnowsky 1 sibling, 1 reply; 10+ messages in thread From: Oliver Kiddle @ 2001-07-18 17:20 UTC (permalink / raw) To: zsh-workers Sven Wischnowsky wrote: > > I just had to play a bit today... > > This makes _describe and compdescribe try to group matches with the same > description. I've used Bart's first suggestion, i.e. it really searches Great. Cheers Sven. gzip --<tab> seems to just be offering --fast and --best. It seems to be all options up to but not including the first where we have a reused description. It is fine with just gzip -<tab>. Similarly for other commands. There is possibly scope for _arguments parsing of --help output (as used by _gnu_generic) to make better use of output where options are listed together, i.e. looking something like this: -?, --help display this option help > I've also made sure that in menu selection the entries for all options > belonging together are shown together. Unfortunately that meant to make > all those strings start with the same (the list of options), which is a > bit ugly. If you try it, you'll see that I at least changed the > descriptions of the second to n'th string to be `|' which sorts in after > most normal characters and hence makes the list look not too stupid. > I'm open to every suggestion to make this even more pleasing -- the best > we could get is probably to make the second to n'th entry show only the > i'th option and something like ` - " - ', but for that we would have to > sort the strings and add them as an unsorted group (i.e. mess with the > compadd-options _describe gets from its caller). Certainly doable, > though. This bit doesn't seem entirely ideal. For menu selection what might be better would possibly be if the separate options were highlghted separately instead of having to expand it out. I think it would also be good if there was a style so the user could perhaps select whether they wanted selection to pick the long or short option (as I think someone else suggested). With the current implementation, a centred ditto mark (") might be better than the pipe (|). It might also be better if when expanding it, you just got `-H' and `--help' on each line instead of `-H, --help' duplicated. We have a lot of completion functions where we've not used the braces to offer descriptions for both long and short options. Specifying descriptions for only short options seems to have been fairly common. Converting them will be a tedious job which I will get round to if nobody else does it first but I have roughly zero spare time at the moment. One other thing which this has reminded me of is that I would quite like it to be able to remove from the completion listings extra options which some commands have like gzip's --to-stdout which is the same as --stdout. So some sort of style which says list/complete only the canonical form of something and some way of saying in _arguments that an option is just an extra synonym. However with this new patch of, --to-stdout is now less annoying anyway because it isn't there with a full description taking a whole line. Oliver ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: PATCH: Re: long/short options 2001-07-18 17:20 ` Oliver Kiddle @ 2001-07-19 8:36 ` Sven Wischnowsky 0 siblings, 0 replies; 10+ messages in thread From: Sven Wischnowsky @ 2001-07-19 8:36 UTC (permalink / raw) To: zsh-workers Oliver Kiddle wrote: > ... > > gzip --<tab> seems to just be offering --fast and --best. It seems to be > all options up to but not including the first where we have a reused > description. It is fine with just gzip -<tab>. Similarly for other > commands. Actually, it was offering them, it just didn't show them. Stupid me, I should have thought about that. The only solution I can see is to make sure the arrays contain only matching strings before calling compdescribe. The patch below does that. > There is possibly scope for _arguments parsing of --help output (as used > by _gnu_generic) to make better use of output where options are listed > together, i.e. looking something like this: > -?, --help display this option help We don't even try to use the descriptions in the --help output yet. I've been thinking about that, too, but getting the options is already difficult and trying to get the descriptions... > > [ how duplicate descriptions appear ] > > This bit doesn't seem entirely ideal. For menu selection what might be > better would possibly be if the separate options were highlghted > separately instead of having to expand it out. I think it would also be > good if there was a style so the user could perhaps select whether they > wanted selection to pick the long or short option (as I think someone > else suggested). With the current implementation, a centred ditto mark > (") might be better than the pipe (|). It might also be better if when > expanding it, you just got `-H' and `--help' on each line instead of > `-H, --help' duplicated. I know all that and am thinking the same. But. That would require some serious changes (note that my patch really only changed _describe and compdescribe -- the other hunks were only bug fixes and cleanup). A first step could be to be able to tell the listing code about a `region of interest'. complist could use that to highlight only that part (useful elsewhere, e.g. process listings). Then we would have to be able to tell it that two matches share the same display string. Adding a style so that menu selection allows to select only one of the options would be a lot easier to write. Making it display only one of the options per line (instead of a duplicated `-H, --help') is something I thought about, too, but that would require that we are able to tell in _describe if we are going to enter menu selection. And that isn't always possible because it might depend on the number of matches generated. If people would be satisfied with an approximation, i.e. simplifying the strings if it thinks it will enter menu selection, but probably sometimes entering menu selection with duplicated `-H, --help', I could probably implement that without much work. And about using `"' instead of the `|': as I said, this would require _describe to modify the option arrays it gets to use unsorted groups and then sort the options itself. Probably not too complicated either (I think I've got most of the code in my head now). If we do that we could probably also use this to make the menu selection listing either because we don't need to put any option name in front of the display string, e.g.: % foo -<TAB> -H, --help -- print help --help -- " or % foo -<TAB> -H, --help -- print help " -- " or whatever. Anyone else want to draw some pictures? ;-) > We have a lot of completion functions where we've not used the braces to > offer descriptions for both long and short options. Specifying > descriptions for only short options seems to have been fairly common. > Converting them will be a tedious job which I will get round to if > nobody else does it first but I have roughly zero spare time at the > moment. I fear this is partly my fault. > One other thing which this has reminded me of is that I would quite like > it to be able to remove from the completion listings extra options which > some commands have like gzip's --to-stdout which is the same as > --stdout. So some sort of style which says list/complete only the > canonical form of something and some way of saying in _arguments that an > option is just an extra synonym. However with this new patch of, > --to-stdout is now less annoying anyway because it isn't there with a > full description taking a whole line. Maybe this could be solved together with the `only short/long' options you mentioned above. Filtering out some options is simple to implement as long as they use the same description (so tht we can use this new code) and as long as it's well defined which options are to be used/removed. Bye Sven Index: Completion/Base/Utility/_describe =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_describe,v retrieving revision 1.2 diff -u -r1.2 _describe --- Completion/Base/Utility/_describe 2001/07/18 13:10:09 1.2 +++ Completion/Base/Utility/_describe 2001/07/19 08:36:43 @@ -21,8 +21,49 @@ # Do the tests. `showd' is set if the descriptions should be shown. zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes + if zstyle -T ":completion:${curcontext}:$_type" list-grouped; then + local _argv _new _strs _mats _opts _i=2 + + _argv=( "$@" ) _grp=(-g) + _new=( "$1" ) + shift + + while (( $# )); do + + _strs="_a_$_i" + eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )' + _argv[_i]="_a_$_i" + shift + (( _i++ )) + + if [[ "$1" = (|-*) ]]; then + _mats= + else + _matss="_a_$_i" + eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )' + _argv[_i]="_a_$_i" + shift + (( _i++ )) + fi + + _opts=( "${(@)argv[1,(i)--]:#--}" ) + shift "$#_opts" + (( _i += $#_opts )) + if [[ $1 == -- ]]; then + shift + (( _i++ )) + fi + + if [[ -n $_mats ]]; then + compadd "$_opts[@]" -O $_strs -D $_mats -a $_strs + else + compadd "$_opts[@]" -O $_strs -a $_strs + fi + done + + set - "$_argv[@]" else _grp=() fi @@ -50,9 +91,11 @@ if [[ -n "$_hide" ]]; then if [[ "$PREFIX" = --* ]]; then _tmpd=( "${(@)_tmpd#--}" ) + _tmph=( "${(@)_tmph#--}" ) _tmps=( "${(@)_tmps#--}" ) elif [[ "$PREFIX" = [-+]* ]]; then _tmpd=( "${(@)_tmpd#[-+]}" ) + _tmph=( "${(@)_tmph#[-+]}" ) _tmps=( "${(@)_tmps#[-+]}" ) fi fi Index: Src/Zle/computil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v retrieving revision 1.64 diff -u -r1.64 computil.c --- Src/Zle/computil.c 2001/07/18 13:52:53 1.64 +++ Src/Zle/computil.c 2001/07/19 08:36:44 @@ -64,7 +64,7 @@ /* Maximum string length when used with descriptions. */ -#define CD_MAXLEN 20 +#define CD_MAXLEN 30 static struct cdstate cd_state; @@ -171,8 +171,8 @@ } } } - if (cd_state.pre > 20) - cd_state.pre = 20; + if (cd_state.pre > CD_MAXLEN) + cd_state.pre = CD_MAXLEN; } /* Initialisation. Store and calculate the string and matches and so on. */ -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2001-07-19 8:37 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-07-12 16:01 long/short options Andrej Borsenkow 2001-07-13 8:07 ` Sven Wischnowsky 2001-07-13 17:01 ` Bart Schaefer 2001-07-16 7:14 ` Sven Wischnowsky 2001-07-18 13:07 ` PATCH: " Sven Wischnowsky 2001-07-18 13:46 ` Andrej Borsenkow 2001-07-18 13:51 ` Sven Wischnowsky 2001-07-18 13:59 ` Andrej Borsenkow 2001-07-18 17:20 ` Oliver Kiddle 2001-07-19 8:36 ` 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).