From: Stefan Monnier Date: Fri, 23 May 2014 16:17:14 +0000 (-0400) Subject: * lisp/emacs-lisp/nadvice.el (advice--member-p): Change second arg. X-Git-Url: http://git.hcoop.net/bpt/emacs.git/commitdiff_plain/15ad4013c44d19125fde6bbb704797d4a7a185b3 * lisp/emacs-lisp/nadvice.el (advice--member-p): Change second arg. (advice-function-member-p): Tell it to check both names and functions. (advice--add-function): Adjust call accordingly. Fixes: debbugs:17531 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0220741d76..57cf0490fe 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2014-05-23 Stefan Monnier + + * emacs-lisp/nadvice.el (advice--member-p): Change second arg. + (advice-function-member-p): Tell it to check both names and functions + (bug#17531). + (advice--add-function): Adjust call accordingly. + 2014-05-23 Stephen Berman * calendar/todo-mode.el: Miscellaneous bug fixes. diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el index 01027c4314..1c8641249c 100644 --- a/lisp/emacs-lisp/nadvice.el +++ b/lisp/emacs-lisp/nadvice.el @@ -180,12 +180,16 @@ WHERE is a symbol to select an entry in `advice--where-alist'." (advice--make-1 (nth 1 desc) (nth 2 desc) function main props))))) -(defun advice--member-p (function name definition) +(defun advice--member-p (function use-name definition) (let ((found nil)) (while (and (not found) (advice--p definition)) - (if (if name - (equal name (cdr (assq 'name (advice--props definition)))) - (equal function (advice--car definition))) + (if (if (eq use-name :use-both) + (or (equal function + (cdr (assq 'name (advice--props definition)))) + (equal function (advice--car definition))) + (equal function (if use-name + (cdr (assq 'name (advice--props definition))) + (advice--car definition)))) (setq found definition) (setq definition (advice--cdr definition)))) found)) @@ -291,7 +295,7 @@ is also interactive. There are 3 cases: ;;;###autoload (defun advice--add-function (where ref function props) (let* ((name (cdr (assq 'name props))) - (a (advice--member-p function name (gv-deref ref)))) + (a (advice--member-p (or name function) (if name t) (gv-deref ref)))) (when a ;; The advice is already present. Remove the old one, first. (setf (gv-deref ref) @@ -323,7 +327,7 @@ properties alist that was specified when it was added." "Return non-nil if ADVICE is already in FUNCTION-DEF. Instead of ADVICE being the actual function, it can also be the `name' of the piece of advice." - (advice--member-p advice advice function-def)) + (advice--member-p advice :use-both function-def)) ;;;; Specific application of add-function to `symbol-function' for advice. diff --git a/test/automated/advice-tests.el b/test/automated/advice-tests.el index e0c3b40487..a87d979f91 100644 --- a/test/automated/advice-tests.el +++ b/test/automated/advice-tests.el @@ -184,6 +184,7 @@ function being an around advice." (sm-advice (lambda (x) (if (consp x) (list (* 5 (car x))) (* 4 x))))) (should (equal (funcall sm-test10 5) 15)) (add-function :filter-args (var sm-test10) sm-advice) + (should (advice-function-member-p sm-advice sm-test10)) (should (equal (funcall sm-test10 5) 35)) (add-function :filter-return (var sm-test10) sm-advice) (should (equal (funcall sm-test10 5) 60))