Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: completion match ordering



Oliver Kiddle wrote on Mon, 26 Nov 2018 02:25 +0100:
> On 7 Nov, I wrote:
> > You can do:
> >   _arguments '-b-:level: compadd "${(@)expl/#-J/-2V}" ${(on)levels}'
> > But what you have is perhaps better, especially as it's duplicated for
> > -b and -e.
> 
> The patch below is an initial experiment for what I was suggesting.
> It allows, e.g:
>   _arguments '-b-:level:compadd -o numeric -a levels'
> 
> Any thoughts on the interface? Is something more terse like -on
> preferable? The -V option becomes superfluous (but remains for
> compatibility). Instead of -V grp you can use -J grp -o nosort.
> Do we need to worry about this breaking uses of the old -o?

In general, I would default to assuming we should worry about
compatibility, unless there's a specific reason not to.  (As a user,
I assume that my zsh code is forward compatible with new zsh releases
unless something is specifically documented to be an exception.)

Is there a reason for this case to be an exception?  If people use
«compadd -od foo -a bar» in 5.6.2, what would the failure mode be?

> With this the existing, -o would become -o match and becomes a property
> of the group rather than the match. Being associated with the group is
> more consistent with related options like -1, -2 and -V. It might be
> confusing that it doesn't work if no group is specified, however.

Sounds like bin_compadd() could detect this situation and warn.

> Currently, given two -o options, only the first applies, This is
> consistent with -X, -J etc even though I think it would have been better
> if the last of these were used. In many cases where functions use
> zparseopts to extract compadd options, they should be using J+: rather
> than J: as zparseopts is taking the last one only with J:

No, what they *should* be doing is passing arguments transparently,
without parsing and reserializing them, so when we add "-$letter"
options to compadd we can do so by changing just one place (namely, the
C struct declaring the builtin).  Probably by putting the compadd
options in an array and passing its name, or by putting them in ${argv}
after ${argv[(i)--]}, etc..

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author