4

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?

  • 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. – Kaushal Modi Jul 18 '16 at 13:11
  • @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 '16 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 '17 at 15:20
  • Another use case is if you (I did) added a lambda advice. – ibizaman Sep 7 '17 at 13:53
4
(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol: ")
  (advice-mapc (lambda (advice _props) (advice-remove sym advice)) sym))
  • Okay, this should also work. But, this is more like a comment and not an answer to the actual question. – Tobias Jul 18 '16 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 '16 at 10:18
  • 3
    I've submitted a patch to add advice-remove-all to nadvice.el. – Tianxiang Xiong Apr 27 '17 at 3:49

Your Answer

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

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