]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/nadvice.el
* lisp/emacs-lisp/nadvice.el (advice--member-p): Return the advice if found.
[gnu-emacs] / lisp / emacs-lisp / nadvice.el
index a3dfb0326e6a1855e88b392aa73347cb01ec14df..c08d671e7eb939c40ac4fb66adf7ea0faa4e4a6b 100644 (file)
@@ -41,6 +41,7 @@
   '((:around "\300\301\302\003#\207" 5)
     (:before "\300\301\002\"\210\300\302\002\"\207" 4)
     (:after "\300\302\002\"\300\301\003\"\210\207" 5)
+    (:override "\300\301\ 2\"\207" 4)
     (:after-until "\300\302\002\"\206\013\000\300\301\002\"\207" 4)
     (:after-while "\300\302\002\"\205\013\000\300\301\002\"\207" 4)
     (:before-until "\300\301\002\"\206\013\000\300\302\002\"\207" 4)
@@ -166,7 +167,7 @@ WHERE is a symbol to select an entry in `advice--where-alist'."
       (if (or (equal function (advice--car definition))
               (when name
                 (equal name (cdr (assq 'name (advice--props definition))))))
-          (setq found t)
+          (setq found definition)
         (setq definition (advice--cdr definition))))
     found))
 
@@ -228,6 +229,7 @@ call OLDFUN here:
 `:before'      (lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))
 `:after'       (lambda (&rest r) (prog1 (apply OLDFUN r) (apply FUNCTION r)))
 `:around'      (lambda (&rest r) (apply FUNCTION OLDFUN r))
+`:override'    (lambda (&rest r) (apply FUNCTION r))
 `:before-while'        (lambda (&rest r) (and (apply FUNCTION r) (apply OLDFUN r)))
 `:before-until'        (lambda (&rest r) (or  (apply FUNCTION r) (apply OLDFUN r)))
 `:after-while' (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
@@ -258,11 +260,16 @@ is also interactive.  There are 3 cases:
 
 ;;;###autoload
 (defun advice--add-function (where ref function props)
-  (unless (advice--member-p function (cdr (assq 'name props))
-                            (gv-deref ref))
+  (let ((a (advice--member-p function (cdr (assq 'name props))
+                             (gv-deref ref))))
+    (when a
+      ;; The advice is already present.  Remove the old one, first.
+      (setf (gv-deref ref)
+            (advice--remove-function (gv-deref ref) (advice--car a))))
     (setf (gv-deref ref)
           (advice--make where function (gv-deref ref) props))))
 
+;;;###autoload
 (defmacro remove-function (place function)
   "Remove the FUNCTION piece of advice from PLACE.
 If FUNCTION was not added to PLACE, do nothing.