From cd0378a2493e391ba05889d9261317d3cef0db50 Mon Sep 17 00:00:00 2001 From: Tianxiang Xiong 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 address@hidden advice-remove-all symbol +Remove all advice from named function @var{symbol}. address@hidden defun + @defun advice-member-p function symbol Return address@hidden 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, * 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 address@hidden'. `(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