I'm trying to find a way to run a function whenever a specific variable is accessed or read in Emacs Lisp. I want to know which functions are using this variable, but I don't know them beforehand.
I'm aware of the add-variable-watcher function, which can be used to monitor when a variable is modified. However, this doesn't seem to cover the case when the variable is simply accessed or read without being modified.
Is there a way to run a "get" function or a hook whenever a variable is read in Emacs Lisp, without knowing which functions are using the variable?
eval_sub.M-x rgrepis your friend -- just search the code if you want to know what code is using some symbol. (It's possible that something will generate the name in a less-obvious way, but for the most part names are not obfuscated and we can leverage basic tooling for things like this).