emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Propagating local variables?


From: Clément Pit-Claudel
Subject: Re: Propagating local variables?
Date: Thu, 17 May 2018 10:27:56 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 2018-05-17 08:18, Shea Levy wrote:
> 2. How do we actually ensure the variables are propagated? I wrote the
>    inherit-local package to do the propagation, but there's no obvious
>    hook point to call it (thus the advice around generate-new-buffer)

We now have variable watchers:

> add-variable-watcher is a built-in function in ‘C source code’.
> 
> (add-variable-watcher SYMBOL WATCH-FUNCTION)
> 
> Cause WATCH-FUNCTION to be called when SYMBOL is set.
> 
> It will be called with 4 arguments: (SYMBOL NEWVAL OPERATION WHERE).
> SYMBOL is the variable being changed.
> NEWVAL is the value it will be changed to.
> OPERATION is a symbol representing the kind of change, one of: ‘set’,
> ‘let’, ‘unlet’, ‘makunbound’, and ‘defvaralias’.
> WHERE is a buffer if the buffer-local value of the variable is being
> changed, nil otherwise.
> 
> All writes to aliases of SYMBOL will call WATCH-FUNCTION too.

These could probably be used for that purpose:

- add watchers to the symbols of each shared variable
- create a buffer local list of dependent buffers to the parent buffer
- every time one of the watched variable changes, propagate the changes to the 
dependent buffers of the buffer it was changed in

It would be fairly understandable, too, since adding a watcher to a variable 
adds an informative message to that variable's docstring.

Of course, this assumes that the set of variables that you want to propagate is 
small and known beforehand.  As an alternative, a 
buffer-local-variable-change-hook might be a useful addition?

Clément.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]