I've noticed that if function f is used to advise function g through advice-add, and function f is then redefined, function g's advice is not updated.

After digging into advice-add a bit, it is clear that advice-add uses add-function behind the scenes, which means that it extracts the value in the function cell of f and uses it to advise g. Therefore, when f is redefined, g is not affected.

I'm wondering why such a design decision was made. Is there a good reason that we shouldn't or couldn't allow updating f to update g's advice as well?

  • 1
    I happily can redefine a function f and get the effect on adviced g with GNU Emacs 24.4.1. I have (defun g ()"g"), (defun f (org-fun &rest args) (concat "f" (apply org-fun args))) and (advice-add 'g :around #'f). Whenever I change f the effect is visible if I call (g). – theldoria Jul 20 '16 at 5:44
  • I do not understand exactly what you mean. Please give some example code/session to show what you did, what you got, and what you wanted to get instead. – Stefan Jul 20 '16 at 22:12
  • Actually, I think I was just confused after screwing around with advices. @theldoria is correct. – Tianxiang Xiong Jul 21 '16 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.