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

Q: _alternative's `(( w1:d1 w2:d2 ))' form



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: signature.asc
Description: PGP signature



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