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

Re: Getting original words after _arguments



On Sat, 20 Apr 2013 08:36:34 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Apr 19,  3:21am, Felipe Contreras wrote:
> }
> } 	orig_words=( ${words[@]} )
> } 	_arguments -C '--stuff' && _ret=0
> } 	words=( ${orig_words[@]} )
> } 
> } I need to have access to the original array of words, before the
> } _arguments stuff is run, and so far the only I can achieve that is by
> } manually storing the old ones, and then restoring them.
> 
> Hmm. The variable named "words" is special to the completion system, and
> if _arguments modifies it that probably means that later stuff is going
> to depend on the state in which $words was left.  You may confuse things
> by stuffing $orig_words back into words.

This has just reminded me that one special aspect of "words" is that it
gets restored after the current function exits.  So if it's feasible to
do the additional thing you want in a separate completion function --- I
have a feeling even the caller would be good enough, so even a trivial
function to nest the call to _arguments --- that's one way out.
(_arguments changes the value of "compstate[restore]", which is why the
altered value of "words" propagates back from it.)

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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