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

Re: [PATCHv3] Refactor baud rate completion



Oliver Kiddle wrote:
[...]
> It is usually more flexible to just accept normal compadd options for
> descriptions and tags and pass them on to compadd fairly directly. It
> then will work in conjunction with other helpers like _alternative.
> _pdf is a good example. Using _wanted here isn't entirely necessary:
> _description would be sufficient and avoids nesting tag loops.

So, _pdf does this:

    _description files expl 'PDF file'
    _files "$@" "$expl[@]" -g "*.(#i)pdf$ext(-.)"

which made me think that the following would be a reasonable call:

    _description -1V baud-rates expl 'baud rate'
    compadd "$@" "$expl[@]" -- "${rates[@]}"

Passing "$@" to compadd makes _arguments parameters like this work:

  '-s[line speed]:line speed:_baudrates' \

Because that makes the helper pass the -X ... option containing "line
speed" to compadd. However "$@" also contains -J option-s-1, which makes
compadd create a sorted group, which is not that useful here.

Passing -V to _description adds -V to "expl", but compadd seems to use
the first argument it finds. But I can't just put "$@" behind expl, in
the compadd call because in that case I won't get the description set in
the _arguments call, if _baudrates was called from _arguments.

I don't know if there is a simple way to make it work the way I'd like
(unsorted group as well as inheriting the right description), so I ended
up doing this:

    _description -1V baud-rates expl 'baud rate'
    compadd "${(@)argv/#-J/-V}" "$expl[@]" -- "${rates[@]}"

That feels pretty dirty, but it seems to work.

The completion-style-guide mentions the following:

    _description -1V tag expl '...'
    compadd "$expl[@]" - ...

But that would discard any descriptions given in an _arguments call.

Better ideas welcome.


Regards, Frank



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