aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-09-10 18:44:36 +0100
committerWilfred Hughes <me@wilfred.me.uk>2017-09-10 18:46:20 +0100
commit62ede4c121c0a0a9917682f28adf746e21bbfa45 (patch)
tree655304cf1fc2f421a14b26237af8a409e9dfe482
parent211d721fd454822e045c2724015c2a14252e2007 (diff)
Ensure we handle aliased primitive functions
Fixes #34
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el8
-rw-r--r--test/unit-test.el8
3 files changed, 17 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a27be4a..0a757de 100644
--- 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
index 37daee4..8be3865 100644
--- 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
index 8e5349a..943e981 100644
--- 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