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

Re: zle messes up 'words' variable?



On Wed, Apr 27, 2011 at 11:26 AM, Felipe Contreras
<felipe.contreras@xxxxxxxxx> wrote:
> I'm trying the following:
> ---
> set_vars ()
> {
>        cur="foo"
>        words="foo"
>        cwords="foo"
> }
>
> _foo ()
> {
>        local cur words cwords
>        set_vars
>
>        echo "cur=${cur} words=${words} cwords=${cwords}" >> /tmp/comp_test.txt
> }
>
> compdef _foo foo
> ---
>
> Which results in:
> cur=foo words= cwords=foo
>
> Strangely enough, if I use the #compdef tag, the code works fine (words="foo").
>
> Any ideas?

I saw the following reply online but I wasn't CC'ed:

> Hrm.  #compdef is equivalent to "compdef -na ..." and causes the function to
> be autoloaded at the time it's referenced.  I don't know of any other reason
> the -na options would change the behavior.  Does the code work fine on
> repeated attempts or only the first time?

Actually, I cannot get it to work any more with #compdef tag. I don't
know what I'm doing wrong. But compdef -na doesn't work either.

> What may be happening is that "sticky emulation" is in effect, so that when
> the function is autoloaded in bash compatibility mode, "words" becomes
> non-special.  If so, I'm not familiar enough with bashcompinit to say whether
> that's intentional or an accidental side-effect.

This has nothing to do with bashcompinit, the issue is with plain compinit.

BTW. This messes up with a very important function in bash completion:
_get_comp_words_by_ref()

Cheers.

-- 
Felipe Contreras



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