]> git.eshelyaron.com Git - emacs.git/commitdiff
Set the 'name' prop in 'define-advice'
authorSteven Allen <steven@stebalien.com>
Sat, 6 Jan 2024 17:19:12 +0000 (09:19 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 13 Jan 2024 18:24:39 +0000 (19:24 +0100)
In addition to naming the advice function `symbol@name', set
the 'name' property to NAME.
* lisp/emacs-lisp/nadvice.el (define-advice): set the 'name'
property to NAME (requested in Bug#68114).  Fixes Bug#68294.

* doc/lispref/functions.texi (Advising Named Functions): Document
that 'define-advice' installs the advice with the specified name.

(cherry picked from commit 9b8b352ebc09de3259f655fa4d491507109044b3)

doc/lispref/functions.texi
etc/NEWS
lisp/emacs-lisp/nadvice.el

index 6c6f1e259176acea3c678ebbee5e57ddd9e8b5dc..344b3ff3a50d86d4b990e3ad84bbbc42c92fa1dd 100644 (file)
@@ -2066,9 +2066,10 @@ code) obey the advice and other calls (from C code) do not.
 
 @defmac define-advice symbol (where lambda-list &optional name depth) &rest body
 This macro defines a piece of advice and adds it to the function named
-@var{symbol}.  The advice is an anonymous function if @var{name} is
-@code{nil} or a function named @code{symbol@@name}.  See
-@code{advice-add} for explanation of other arguments.
+@var{symbol}.  If @var{name} is non-nil, the advice is named
+@code{@var{symbol}@@@var{name}} and installed with the name @var{name}; otherwise,
+the advice is anonymous.  See @code{advice-add} for explanation of
+other arguments.
 @end defmac
 
 @defun advice-add symbol where function &optional props
index 193aa1331e453a162a2c061c44af835f0429e187..7d1cac806dbc42feccf9ee565178256d426eb751 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1480,6 +1480,12 @@ the region and never want to restrict 'undo' to that region, it is
 preferable to use the existing 'undo-inhibit-region' symbol property
 instead of this variable.
 
++++
+** 'define-advice' now sets the new advice's 'name' property to NAME
+Named advice defined with 'define-advice' can now be removed with
+'(advice-remove SYMBOL NAME)' in addition to '(advice-remove SYMBOL
+SYMBOL@NAME)'.
+
 +++
 ** New function 'require-with-check' to detect new versions shadowing.
 This is like 'require', but it checks whether the argument 'feature'
index de287e43b21911a4b2b248574f3d2187ff6894f1..7524ab18e58959dd9e97ebba16f952a509babc8f 100644 (file)
@@ -585,8 +585,8 @@ of the piece of advice."
 (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
-arguments.  Note if NAME is nil the advice is anonymous;
-otherwise it is named `SYMBOL@NAME'.
+arguments.  If NAME is non-nil, the advice is named `SYMBOL@NAME'
+and installed with the name NAME; otherwise, the advice is anonymous.
 
 \(fn SYMBOL (HOW LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
   (declare (indent 2) (doc-string 3) (debug (sexp sexp def-body)))
@@ -597,7 +597,9 @@ otherwise it is named `SYMBOL@NAME'.
          (lambda-list   (nth 1 args))
          (name          (nth 2 args))
          (depth         (nth 3 args))
-         (props         (and depth `((depth . ,depth))))
+         (props         (append
+                         (and depth `((depth . ,depth)))
+                         (and name `((name . ,name)))))
          (advice (cond ((null name) `(lambda ,lambda-list ,@body))
                        ((or (stringp name) (symbolp name))
                         (intern (format "%s@%s" symbol name)))