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?

Drew
  • 77,472
  • 10
  • 114
  • 243
Tobias
  • 33,167
  • 1
  • 37
  • 77
  • 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
  • 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 '16 at 03: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
  • 2
    Another use case is if you (I did) added a lambda advice. – ibizaman Sep 07 '17 at 13:53

1 Answers1

15
(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol: ")
  (advice-mapc (lambda (advice _props) (advice-remove sym advice)) sym))
zck
  • 9,092
  • 2
  • 33
  • 65
xuchunyang
  • 14,527
  • 1
  • 19
  • 39