From 6312200926f4f674faddd95d8754793236d2571d Mon Sep 17 00:00:00 2001 From: CeleritasCelery Date: Mon, 25 Feb 2019 10:32:53 -0800 Subject: 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. --- CHANGELOG.md | 2 ++ helpful.el | 2 +- test/helpful-unit-test.el | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3188861..3d6662d 100644 --- 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 index 4c51689..fe73020 100644 --- 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 index 541639c..008a052 100644 --- 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) -- cgit v1.0