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

Re: expansion of environment variables



On Thu, 05 Mar 2009 08:15:48 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

(re

% touch stuff.txt
% foo=stuff
% echo $foo.<TAB>

etc.)

> Worse, if I enable the new completion system with 'compinit' then the
> variable doesn't expand but the completion doesn't work.  I mention
> this because with the new completion system enabled, the 'suffix'
> zstyle is supposed to control exactly what Ruud is asking about, and
> the default is to have the "old" behavior that he wants.
>  
> For benefit of zsh-workers, with compinit this is yet another problem
> in _path_files.  At line 479 (latest CVS) it correctly assigns the
> expanded list of files to the tmp2 array (having originally gotten
> them from "compadd -D tmp1" at line 466), but then when building the
> exppaths array at lines 484 or 486, it uses ${tpre}${tsuf} which have
> never been expanded.

That's too late---it's failed at that point.  See the comment above that
section.  We're in the code that triggers where compfiles (the builtin that
handles the globbing) didn't produce any matches so $#tmp1 is empty.  I
think it's just attempting to expand what it thinks is a plain string chunk
of path, so that things like $foo/<TAB> work.

> I'm also not sure how line 484 can ever be reached, since at 479
> "${(@)tmp2:h}" is always going to strip off any trailing slash.

I don't know about this...

> It
> seems a bit strange to compare an entire array to a single pattern
> at line 483 as well, but I guess it works since the last element of
> the array should be representative of any single element.

...but I think this is related to the fact that we don't have any glob
matches, just a chunk of path that may want something doing to it.

It looks to me like this is a basic problem that's hard to fix: you'd need
an eval'd version of the prefix and suffix to do the globbing on, and then
you'd need to be able to put the expanded bits of it back the way they were
at the end.  In general the only way of doing this would be to expand and
save each variable reference, command expansion, numeric expansion, etc.,
separately.

I suspect, by the way, that the original query was about the old builtin
completion, not the function system.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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