Re: [PATCH] Fix WATCH/watch tying

Philippe Altherr <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAGdYchvcZr62xEpwzTu=etF0--_UfE0VETZ6eAXLY4G0HWBifg@mail.gmail.com>
>
> I did some testing of this and applied it. It had been me that separated
> watch into a module and I know I was dissatisfied with the variable
> setup at the time. That may have been more related to importing the
> value from the environment. Do you see a way to have this apply a value
> of WATCH that has come from the environment.
>

Do you mean that if WATCH is defined in the environment when Zsh starts (or
when the watch module is reloaded), then the WATCH and watch parameters
should be auto-loaded and initialized with the environment value of WATCH?
In other words, would you like the following?

% WATCH=foo:bar zsh-dev -c 'typeset -p WATCH'
typeset -T WATCH watch=( foo bar )

Currently this doesn't work because add_autoparam doesn't create an
autoload parameter if a parameter with the same name already exists
<https://github.com/zsh-users/zsh/blob/40625a597581e8d3fd3dc8dc71a97d6e15c57242/Src/module.c#L1210>.
Interestingly checkaddparam only emits a warning if the already existing
parameter isn't a top-level one
<https://github.com/zsh-users/zsh/blob/40625a597581e8d3fd3dc8dc71a97d6e15c57242/Src/module.c#L1033>.
I'm not sure why that is. Maybe that should be changed. However, that's why
the example above fails without any warning.

I guess that the code of add_autoparam could be changed to do what you
wish. I would only do it if the existing parameter is at the top-level and
if it has the same type as the autoload parameter to be created. In that
case, the value of the existing parameter could be saved, the existing
parameter could then be replaced with the autoload parameter, which would
then be immediately loaded and initialized with the saved value.

Philippe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.