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

Re: zle messes up 'words' variable?



On Tue, May 3, 2011 at 4:42 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On May 2,  9:11pm, Felipe Contreras wrote:
> } I am using bashcompinit, but the issue appears without it.
>
> Without bashcompinit, there is by definition not an issue.  Or, if you
> prefer, you should have expected this issue to appear, because words is
> documented as a special variable in completion function context.

The fact that it's documented as a special variable doesn't mean that
the behavior should be totally unexpected.

1) Without modifier

Then 'words' can be re-used like any other variable.

2) With 'local' modifier

Then modifying 'words' has an impact only on the current function, not
on the scope where the variable was defined as local.

2.1) When using #compdef tag

Then 'words' can be modified like any other variable.

3) With 'typedef -h'

Then 'words' can be modified like any other variable.

I was expecting an explanation of these discrepancies, and a way to
globally make 'words' work as expected without having to replace each
use of 'local' by 'typedef -h'.

I don't think anybody knows what's going on, so nobody knows how to do
that. In fact, this is probably a bug.

> If what you want to discuss is ways to fix bashcompinit so that the
> functions in bash completion work as expected, that's one thing.  If
> what you're asking is for the special-ness of "words" to be undone
> for completion in general, that's so unlikely to happen as to not be
> worth continuing.

You are not good at compartmentalizing aren't you? If you fix the
issue with my example, you fix the issue with bashcompinit. It's the
same issue. Or "riddle" if that word makes you more comfortable.

But if you want to mix the two things together, fine:

---
#!bash

autoload -U +X bashcompinit && bashcompinit

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
}

complete -F _foo foo
---

cur=foo words= cwords=foo

Now that is clearly a bug.

-- 
Felipe Contreras



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