unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [PATCH] Add `advice-remove-all`
@ 2019-09-04 16:59 Matthew Newton
  2019-09-04 18:30 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Matthew Newton @ 2019-09-04 16:59 UTC (permalink / raw)
  To: emacs-devel

My use case is when I’m developing something in my config and I mess up something up. I might iterate on an advice function and end up with multiple advice elements. This is a quick, convenient way to clean it up. Is there a different way that would make more sense?


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH] Add `advice-remove-all`
@ 2017-04-27  3:23 Tianxiang Xiong
  2017-04-27 12:52 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Tianxiang Xiong @ 2017-04-27  3:23 UTC (permalink / raw)
  To: Emacs developers


[-- Attachment #1.1: Type: text/plain, Size: 451 bytes --]

I recently had the need to remove all advice from a function I was playing
around with, and was surprised to find that `advice-remove-all` did not
exist.

Others have had need of it
<https://emacs.stackexchange.com/questions/24657/unadvice-a-function/24658#24658>
as well, so it seems like a good candidate for inclusion in `nadvice.el`.

The attached patch adds `advice-remove-all` to `nadvice.el`, using the
implementation suggested by xuchungyang.

[-- Attachment #1.2: Type: text/html, Size: 533 bytes --]

[-- Attachment #2: 0001-Add-advice-remove-all.patch --]
[-- Type: text/x-patch, Size: 3429 bytes --]

From cd0378a2493e391ba05889d9261317d3cef0db50 Mon Sep 17 00:00:00 2001
From: Tianxiang Xiong <tianxiang.xiong@gmail.com>
Date: Wed, 26 Apr 2017 20:13:05 -0700
Subject: [PATCH] Add `advice-remove-all`

Removes all advice from a function.
---
 doc/lispref/functions.texi |  4 ++++
 etc/NEWS                   |  4 ++++
 lisp/emacs-lisp/nadvice.el | 18 ++++++++++++------
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 283f74f..3f3bee3 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1734,6 +1734,10 @@ Remove the advice @var{function} from the named function @var{symbol}.
 @var{function} can also be the @code{name} of a piece of advice.
 @end defun
 
+@defun advice-remove-all symbol
+Remove all advice from named function @var{symbol}.
+@end defun
+
 @defun advice-member-p function symbol
 Return non-@code{nil} if the advice @var{function} is already in the named
 function @var{symbol}.  @var{function} can also be the @code{name} of
diff --git a/etc/NEWS b/etc/NEWS
index 9d4c72d..729c379 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -24,6 +24,10 @@ When you add a new item, use the appropriate mark if you are sure it applies,
 \f
 * Installation Changes in Emacs 26.1
 
++++
+** The function 'advice-remove-all' is added to 'nadvice.el'
+This allows all advice to be removed from a function.
+
 ** By default libgnutls is now required when building Emacs.
 Use 'configure --with-gnutls=no' to build even when GnuTLS is missing.
 
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index fd1cd2c..957fd85 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -335,6 +335,12 @@ properties alist that was specified when it was added."
     (funcall f (advice--car function-def) (advice--props function-def))
     (setq function-def (advice--cdr function-def))))
 
+(defun advice-mapc (fun symbol)
+  "Apply FUN to every advice function in SYMBOL.
+FUN is called with a two arguments: the function that was added, and the
+properties alist that was specified when it was added."
+  (advice-function-mapc fun (advice--symbol-function symbol)))
+
 (defun advice-function-member-p (advice function-def)
   "Return non-nil if ADVICE is already in FUNCTION-DEF.
 Instead of ADVICE being the actual function, it can also be the `name'
@@ -453,6 +459,12 @@ of the piece of advice."
   nil)
 
 ;;;###autoload
+(defun advice-remove-all (symbol)
+  "Remove all advice from function named SYMBOL."
+  (advice-mapc (lambda (advice _props) (advice-remove symbol advice))
+               symbol))
+
+;;;###autoload
 (defmacro define-advice (symbol args &rest body)
   "Define an advice and add it to function named SYMBOL.
 See `advice-add' and `add-function' for explanation on the
@@ -476,12 +488,6 @@ otherwise it is named `SYMBOL@NAME'.
     `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
        (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
 
-(defun advice-mapc (fun symbol)
-  "Apply FUN to every advice function in SYMBOL.
-FUN is called with a two arguments: the function that was added, and the
-properties alist that was specified when it was added."
-  (advice-function-mapc fun (advice--symbol-function symbol)))
-
 ;;;###autoload
 (defun advice-member-p (advice symbol)
   "Return non-nil if ADVICE has been added to SYMBOL.
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-09-05  0:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-04 16:59 [PATCH] Add `advice-remove-all` Matthew Newton
2019-09-04 18:30 ` Stefan Monnier
2019-09-05  0:14   ` T.V Raman
  -- strict thread matches above, loose matches on Subject: below --
2017-04-27  3:23 Tianxiang Xiong
2017-04-27 12:52 ` Stefan Monnier
2017-05-01 13:26   ` Marcin Borkowski
2017-05-01 17:21     ` Stefan Monnier
2017-05-02  5:31       ` Marcin Borkowski
2017-05-02 13:47         ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).