11

I cannot find a predefined command in nadvice to easily unadvise a function in Emacs 24.5.1. Something like:

(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol:")
  (advice-mapc `(lambda (fun props) (advice-remove ,(quote sym) fun)) sym))

Is there such a thing predefined?

4
  • 2
    I haven't come across a use case where you would need to interactively add/remove advices. Normally you put advice-add or advice-remove in a package or config and then forget about it. Jul 18, 2016 at 13:11
  • 1
    @KaushalModi It is useful for trouble-shooting in the case that you have several modifications of a badly performing function and you want to see whether the original version does behave normally.
    – Tobias
    Nov 16, 2016 at 3:21
  • @KaushalModi: Isearch+ provides a good use case, I think. It lets you dynamically add and remove any number of Isearch filter predicates (aka search filters) while searching incrementally. This means add/remove advice interactively - see Dynamic Isearch Filtering.
    – Drew
    Apr 27, 2017 at 15:20
  • 2
    Another use case is if you (I did) added a lambda advice.
    – ibizaman
    Sep 7, 2017 at 13:53

1 Answer 1

15
(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol: ")
  (advice-mapc (lambda (advice _props) (advice-remove sym advice)) sym))
4
  • Okay, this should also work. But, this is more like a comment and not an answer to the actual question.
    – Tobias
    Jul 18, 2016 at 10:12
  • Maybe the question was not clear enough. Then it is not your fault that you gave this comment as an answer. I've edited my question to make it more clear. -- Thanks for the response!
    – Tobias
    Jul 18, 2016 at 10:18
  • 6
    I've submitted a patch to add advice-remove-all to nadvice.el. Apr 27, 2017 at 3:49
  • 3
    A shame it hasn't been implemented.
    – RichieHH
    Apr 17, 2021 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.