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

Re: PATCH: Completion/User/_cvs again.



I wrote:

> Tanaka Akira wrote:
> 
> > I think the style of `_rpm' is useful for state machines. But it
> > cannot represent function call. And `_cvs' has such functions.
> > 
> > For example, `_cvs_extract_directory_entries' is called from
> > `_cvs_setup_allentries', `_cvs_setup_direntries' and
> > `_cvs_setup_modentries'. And it should return to its caller.
> > This is hard to implement in state machine style, I think.
> 
> Ah, I see. Sorry.
> 
> Yes, adding a heap of extra states a la `extract_file_or_directory_entry'
> is ugly.
> 
> Hm, some form of `case' that executes all matching branches would be
> useful here.
> 
> (Yes, I know that one can do that e.g. with a `case' in a loop where
> the case branches remove substrings from the `state' name, but that
> isn't exactly a nice solution, either.)

I always forget things...

Of course, one can also do (in file `_foo'):

  #compdef foo

  local state lstate ret=1

  if (( $# )); then
    state="$1"
  else
    _arguments '...:->bar' ... && ret=0
  fi

  while [[ -n "$state" ]]; do
    lstate="$state"
    state=''
    case "$lstate" in
    bar)
      # include completions for state `baz' and `foobar'
      _foo baz && ret=0
      _foo foobar && ret=0  # this could also be `state=foobar'
      ;;
    baz) ... ;;
    foobar) ...;;
    esac
  done

  return ret


Don't know if that is cleaner than your solution, though.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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