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
  • 75,699
  • 9
  • 109
  • 225
Tobias
  • 32,569
  • 1
  • 34
  • 75
  • 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+](https://www.emacswiki.org/emacs/IsearchPlus) 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](https://www.emacswiki.org/emacs/DynamicIsearchFiltering). – 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

14
(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol: ")
  (advice-mapc (lambda (advice _props) (advice-remove sym advice)) sym))
zck
  • 8,984
  • 2
  • 31
  • 65
xuchunyang
  • 14,302
  • 1
  • 18
  • 39
  • 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
  • 6
    I've [submitted a patch](https://lists.gnu.org/archive/html/emacs-devel/2017-04/msg00754.html) to add `advice-remove-all` to `nadvice.el`. – Tianxiang Xiong Apr 27 '17 at 03:49
  • 3
    A shame it hasn't been implemented. – RichieHH Apr 17 '21 at 11:33