0

I have variables foo and bar. I have a function that modifies foo and I can't change that function.

How can I redirect the change made to foo so it applies to bar instead?

EDIT :

I want this redirection to track real time change.

What I am trying to achieve :

I want to swap the headerline with the modeline. I did this with this snippet of code :

(defvar og-modeline mode-line-format)
(setq-default mode-line-format header-line-format)
(setq-default header-line-format og-modeline)

It works well but when something from an other package makes change to the headerline it obviously uses header-line-format but I want instead those change to be done to mode-line-format. Thus why I ask if there is the possibility to redirect changes.

Drew
  • 75,699
  • 9
  • 109
  • 225
Virgil
  • 3
  • 3
  • I get the feeling somehow that this is an [XY question](https://en.wikipedia.org/wiki/XY_problem). – NickD Jul 31 '22 at 16:00
  • It is, but I don't know how to do it in elisp and, maybe I should have add this bit of explanation : I need this to remind active whenever there is a change made to foo or bar – Virgil Jul 31 '22 at 16:32
  • https://emacs.stackexchange.com/tags/elisp/info – Drew Jul 31 '22 at 16:34
  • Only one question per post, please. – Drew Jul 31 '22 at 16:36
  • I think you'll need to be more specific in your question. As @NickD hinted, try asking something (much) closer to what you are actually wanting to do. – Drew Jul 31 '22 at 16:38
  • excuse me @Drew, I have edited the question with an example – Virgil Jul 31 '22 at 17:00

1 Answers1

0

Have a look at this section of the manual: Running a function when a variable is changed

You pass a function to (add-variable-watcher 'mode-line-format #'my-watch-function), and that function gets passed various attributes of the variable when it changes.

Phil Hudson
  • 1,651
  • 10
  • 13