Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
From: Frank Terbeck <ft@bewatermyfriend.org>
To: Oliver Kiddle <okiddle@yahoo.co.uk>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCHv3] Refactor baud rate completion
In-Reply-To: <27858.1462193719@thecus.kiddle.eu> (Oliver Kiddle's message of
	"Mon, 02 May 2016 14:55:19 +0200")
References: <87k2jegi5h.fsf@ft.bewatermyfriend.org>
	<1462109252-12482-1-git-send-email-ft@bewatermyfriend.org>
	<27858.1462193719@thecus.kiddle.eu>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)
Date: Sat, 07 May 2016 23:53:12 +0200
Message-ID: <87eg9dmt6f.fsf@ft.bewatermyfriend.org>
MIME-Version: 1.0
Content-Type: text/plain
X-Df-Sender: NDMwNDQ0
X-Seq: zsh-workers 38423

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

