helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 62ede4c121c0a0a9917682f28adf746e21bbfa45
parent 211d721fd454822e045c2724015c2a14252e2007
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sun, 10 Sep 2017 18:44:36 +0100

Ensure we handle aliased primitive functions

Fixes #34

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 8+++++++-
Mtest/unit-test.el | 8++++++++
3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,5 +1,7 @@ # v0.2 +Fixed a crash on viewing aliased primitive functions. + Fixed an issue where we didn't find the path for functions defined interactively using `cl-defstruct`. diff --git a/helpful.el b/helpful.el @@ -515,7 +515,13 @@ POSITION-HEADS takes the form ((123 (defun foo)) (456 (defun bar)))." (defun helpful--primitive-p (sym callable-p) "Return t if SYM is defined in C." (if callable-p - (subrp (symbol-function sym)) + (let ((fn sym)) + ;; Find the function value associated with this symbol. If + ;; it's an alias, follow the alias chain to the function + ;; value. + (while (symbolp fn) + (setq fn (symbol-function fn))) + (subrp fn)) (let ((filename (find-lisp-object-file-name sym 'defvar))) (or (eq filename 'C-source) (and (stringp filename) diff --git a/test/unit-test.el b/test/unit-test.el @@ -49,6 +49,14 @@ (defun test-foo-no-properties () nil) +(ert-deftest helpful--primitive-p () + ;; Defined in C. + (should (helpful--primitive-p 'message t)) + ;; Defined in C, but an alias. + (should (helpful--primitive-p 'not t)) + ;; Defined in elisp. + (should (not (helpful--primitive-p 'when t)))) + (ert-deftest helpful--no-symbol-properties () "Helpful should handle functions without any symbol properties." ;; Interactively evaluating this file will set edebug properties on