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

When to (and not to) use _arguments -C with states

I think that i mostly already figured it out but this piece of zshcompsys(1) always confused me.

 Where _arguments encounters action in the `->string' format, it will strip all leading and trailing whitespace from string and
 set the array state to the set of all strings for which an action is to be performed.  The elements of the  array  state_descr
 are assigned the corresponding message field from each optarg containing such an action.

In the majority of completers that i have written that used ->string actions, only one action was
`action`able at a given time. meaning $state is only a single element, with code that assumes as much like:

case $state in ...

Which made me question when is multiple ->string actions possible?

An contrived example being:
_foo() {
  local s expl state state_descr line
  local -A opt_args

  _arguments '1: :->foo' '-a[optional argument]:: :->bar' && return

  for s in $state; do
    case $s in
      foo) _wanted digit-tag expl 123s compadd 1 2 3;;
      bar) _wanted alpha-tag expl abcs compadd a b c;
compdef _foo foo # foo -a <tab>

since -a uses ->string but it's argument is optional, the '1: :->foo' spec is also valid
so foo and bar are correctly in $state at once.

Are there other ways in which $state can contain > 1 elements?
I ask because i would like to know when it is safe to use _argument -C

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