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

Re: PATCH: compadd (+ questions)



Bart Schaefer wrote:

> [ completion tests and resetting the completion parameters... ]
>
> That's just a matter of more shell functions:
> 
>     listsignals() { complist -k "($signals[1,-3])" }
>     tryprefix - listsignals
> 
> but you're right that a real syntactic construct would be much cleaner.
> 
> Maybe we can figure out a way to make "local" work inside { ... } ?  I've
> seen some postings on zsh-users that lead me to believe some people think
> it does already.

We could use aliases in the meantime:

  alias compsave='local _oprefix$_level _oiprefix$_level _oargv$_level _ocurrent$_level; \
                eval "_oprefix${_level}=\"\$PREFIX\"; \
                _oiprefix${_level}=\"\$IPREFIX\"; \
                _oargv${_level}=( \"\$@\" ); \
                _ocurrent${_level}=\"\$CURRENT\""'
  alias compreset='eval "PREFIX=\"\$_oprefix${_level}\"; \
                 IPREFIX=\"\$_oiprefix${_level}\"; \
                 argv=( \"\$_oargv${_level}[@]\" ); \
		 CURRENT=\"\$_ocur${_level}\""'

  alias __if='(( $+_level )) || local _level=0; (( _level++ )); compsave; if'
  alias __elif='compreset; elif'
  alias __else='compreset; else'
  alias __fi='compreset; fi; unset _oprefix$_level _oiprefix$_level _oargv$_level _ocurrent$_level; (( _level-- ))'

With this one can use `__if ... __elif ... __else ... __fi' for tests
in completion functions (even nested) without having to worry about
calling comp{save,reset}.

But of course that's quite expensive...

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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