zsh-workers
 help / color / mirror / code / Atom feed
* Q: _alternative's `(( w1:d1 w2:d2 ))' form
@ 2021-11-12 19:32 Arseny Maslennikov
  2021-11-12 19:58 ` Arseny Maslennikov
  2021-11-12 20:09 ` Oliver Kiddle
  0 siblings, 2 replies; 4+ messages in thread
From: Arseny Maslennikov @ 2021-11-12 19:32 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1808 bytes --]

Hi!

The doc page for _alternative (citing `info zsh`, menu item `Completion
Functions') states:
_alternative [ -O NAME ] [ -C NAME ] SPEC ...
     <...>
     The tags to use and the action to perform if a tag is requested are
     described using the SPECs which are of the form:
     'TAG:DESCR:ACTION'.  The TAGs are offered using _tags and if the
     tag is requested, the ACTION is executed with the given description
     DESCR.  The ACTIONs are those accepted by the _arguments function
     (described below), excluding the '->STATE' and '=...' forms.
     <...>

Later on, the text for _arguments advises to escape the separating
colons between the match candidate and its description in a (( ))
action spec, due to more complex spec parsing and further optional
fields. A thorough reader of the docs might think the same is
required by _alternative as well.

I've been looking at the implementation of _alternative lately; the
function splits its specs into exactly 3 fields, delimited by `:'. The
following seems to be true:

* the first field is delimited by the first colon;
* the second field spans from after the first field's delimiter to the
  nearest colon;
* the rest of the spec is interpreted as the action field, unlike
  the specs for _arguments.

This means that the following completion function should offer either
letters from the set (a b c y z) or hexadecimal digits with their
decimal equivalents as descriptions:

  function _ooo {  
    _alternative \
      'letters:letter:(a b c y z)' \
      'digits:digit:(( 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:8 9:9 A:10 B:11 C:12 D:13 E:14 F:15 ))'
  }

It does for me in a `zsh -f` instance.

Is this intentional? If yes, should we fix the doc paragraph
on _alternative?

Thanks in advance!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-12 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 19:32 Q: _alternative's `(( w1:d1 w2:d2 ))' form Arseny Maslennikov
2021-11-12 19:58 ` Arseny Maslennikov
2021-11-12 20:09 ` Oliver Kiddle
2021-11-12 21:19   ` [PATCH] Doc/Zsh/compsys.yo: clarify _alternative's action syntax Arseny Maslennikov

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).