2024-12-23 Watching variable changes

Today I have a short Elisp trick, probably slightly more interesting than useful, but still.

A long time ago I wrote about some debugging capabilities of Emacs Lisp. The feature mentioned in the last of these posts, debug-on-variable-change, allows to invoke the debugger whenever some Elisp code changes the value of a variable (with a few minor limitations). What I didn’t mention then is that you can actually do things other than start the Emacs debugger when a variable’s value changes. The function add-variable-watcher (and two of its friends) is the way debug-on-variable-change is defined. This means that you can use it for example to update the display on a change of a variable’s value. I’m not sure if I can think of any other uses of this feature, but I don’t think it needs any more justification – even the debugging thing is very useful.

That’s it for today, thanks for reading!

CategoryEnglish, CategoryBlog, CategoryEmacs