commit 6312200926f4f674faddd95d8754793236d2571d
parent 3600547049768657575e643a1d7f41941575d09f
Author: CeleritasCelery <t.macman@gmail.com>
Date: Mon, 25 Feb 2019 10:32:53 -0800
Remove all advice before determining source of function
Previously, we would only remove the outermost advice. This led to
`helpful--primitive-p` returning the wrong answer for primitive
functions with more than one active advice.
Fixes #185.
Diffstat:
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -12,6 +12,8 @@ buffer-local values.
Better source detection for functions defined by `defstruct` or other
macros.
+Fixed issues with functions that had more than one advice active.
+
# v0.15
Fixed a crash on formatting values.
diff --git a/helpful.el b/helpful.el
@@ -1518,7 +1518,7 @@ E.g. (x x y z y) -> ((x . 2) (y . 2) (z . 1))"
(defun helpful--without-advice (sym)
"Given advised function SYM, return the function object
without the advice."
- (advice--cdr
+ (advice--cd*r
(advice--symbol-function sym)))
(defun helpful--advised-p (sym)
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
@@ -141,6 +141,18 @@ symbol (not a form)."
;; `rename-buffer' is primitive, but it's advised by uniquify.
(should (helpful--primitive-p 'rename-buffer t)))
+(ert-deftest helpful--without-advice ()
+ "Ensure we remove advice to get the underlying function."
+ ;; Removing the advice on an unadvised function should give us the
+ ;; same function.
+ (should
+ (eq (helpful--without-advice #'test-foo)
+ (indirect-function #'test-foo)))
+ ;; Removing the advice should give us an unadvised function.
+ (should
+ (not (helpful--advised-p
+ (helpful--without-advice #'test-foo-advised)))))
+
(ert-deftest helpful-callable ()
;; Functions. Also a regression test for #170.
(helpful-callable 'face-attribute)