Merge from emacs-24; up to 2012-12-19T13:01:16Z!michael.albinus@gmx.de
[bpt/emacs.git] / lisp / emacs-lisp / nadvice.el
index b4d6fac..b0711fe 100644 (file)
@@ -167,20 +167,27 @@ WHERE is a symbol to select an entry in `advice--where-alist'."
         (setq definition (advice--cdr definition))))
     found))
 
-;;;###autoload
-(defun advice--remove-function (flist function)
+(defun advice--tweak (flist tweaker)
   (if (not (advice--p flist))
-      flist
+      (funcall tweaker nil flist nil)
     (let ((first (advice--car flist))
+          (rest (advice--cdr flist))
           (props (advice--props flist)))
-      (if (or (equal function first)
-              (equal function (cdr (assq 'name props))))
-          (advice--cdr flist)
-        (let* ((rest (advice--cdr flist))
-               (nrest (advice--remove-function rest function)))
-          (if (eq rest nrest) flist
-            (advice--make-1 (aref flist 1) (aref flist 3)
-                            first nrest props)))))))
+      (let ((val (funcall tweaker first rest props)))
+        (if val (car val)
+          (let ((nrest (advice--tweak rest tweaker)))
+            (if (eq rest nrest) flist
+              (advice--make-1 (aref flist 1) (aref flist 3)
+                              first nrest props))))))))
+
+;;;###autoload
+(defun advice--remove-function (flist function)
+  (advice--tweak flist
+                 (lambda (first rest props)
+                   (cond ((not first) rest)
+                         ((or (equal function first)
+                           (equal function (cdr (assq 'name props))))
+                          (list rest))))))
 
 (defvar advice--buffer-local-function-sample nil)
 
@@ -269,15 +276,8 @@ of the piece of advice."
 ;;;; Specific application of add-function to `symbol-function' for advice.
 
 (defun advice--subst-main (old new)
-  (if (not (advice--p old))
-      new
-    (let* ((first (advice--car old))
-           (rest (advice--cdr old))
-           (props (advice--props old))
-           (nrest (advice--subst-main rest new)))
-      (if (equal rest nrest) old
-        (advice--make-1 (aref old 1) (aref old 3)
-                        first nrest props)))))
+  (advice--tweak old
+                 (lambda (first _rest _props) (if (not first) new))))
 
 (defun advice--normalize (symbol def)
   (cond