aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-08-26 21:11:00 +0100
committerWilfred Hughes <me@wilfred.me.uk>2017-08-26 21:11:00 +0100
commit6b0cd0530480eabdc7b588869e728ca497e4f92a (patch)
treefabcad2e9bffa137f7a30375741c826888711c09
parentc795c6be03c0a06352a42b1257a0532149171799 (diff)
Allow viewing variables defined in C
-rw-r--r--helpful.el28
-rw-r--r--test/unit-test.el3
2 files changed, 18 insertions, 13 deletions
diff --git a/helpful.el b/helpful.el
index 01028f8..ae995cc 100644
--- a/helpful.el
+++ b/helpful.el
@@ -443,9 +443,14 @@ POSITION-HEADS takes the form ((123 (defun foo)) (456 (defun bar)))."
(helpful--format-reference head count pos path)))
(s-join "\n")))
-(defun helpful--primitive-p (sym)
+(defun helpful--primitive-p (sym callable-p)
"Return t if SYM is defined in C."
- (subrp (symbol-function sym)))
+ (if callable-p
+ (subrp (symbol-function sym))
+ (let ((filename (find-lisp-object-file-name sym 'defvar)))
+ (or (eq filename 'C-source)
+ (and (stringp filename)
+ (equal (file-name-extension filename) "c"))))))
(defun helpful-update ()
"Update the current *Helpful* buffer to the latest
@@ -454,7 +459,9 @@ state of the current symbol."
(cl-assert (not (null helpful--sym)))
(let* ((inhibit-read-only t)
(start-pos (point))
- (look-for-src (or (not (helpful--primitive-p helpful--sym))
+ (primitive-p (helpful--primitive-p
+ helpful--sym helpful--callable-p))
+ (look-for-src (or (not primitive-p)
find-function-C-source-directory))
(source (when look-for-src
(helpful--source helpful--sym helpful--callable-p)))
@@ -464,7 +471,7 @@ state of the current symbol."
(when source-path
(let* ((buf (elisp-refs--contents-buffer source-path))
(positions
- (if (helpful--primitive-p helpful--sym)
+ (if primitive-p
nil
(helpful--reference-positions helpful--sym buf))))
(setq references
@@ -525,9 +532,7 @@ state of the current symbol."
(insert
(helpful--heading "\n\nDebugging\n")
- (if (or
- (not helpful--callable-p)
- (helpful--primitive-p helpful--sym))
+ (if (or (not helpful--callable-p) primitive-p)
""
(concat
(helpful--disassemble-button)
@@ -539,15 +544,13 @@ state of the current symbol."
(source-path
(concat
(propertize
- (if (helpful--primitive-p helpful--sym)
- "// Defined in "
- ";; Defined in ")
+ (if primitive-p "// Defined in " ";; Defined in ")
'face 'font-lock-comment-face)
(helpful--navigate-button
source-path
(helpful--source-pos helpful--sym helpful--callable-p))
"\n"))
- ((helpful--primitive-p helpful--sym)
+ (primitive-p
(propertize
"C code is not yet loaded."
'face 'font-lock-comment-face))
@@ -559,8 +562,7 @@ state of the current symbol."
(if (stringp source)
(helpful--syntax-highlight
source
- (if (helpful--primitive-p helpful--sym)
- 'c-mode))
+ (if primitive-p 'c-mode))
(helpful--syntax-highlight (helpful--pretty-print source)))))
(goto-char start-pos)))
diff --git a/test/unit-test.el b/test/unit-test.el
index ab7d6f8..5e453b2 100644
--- a/test/unit-test.el
+++ b/test/unit-test.el
@@ -101,3 +101,6 @@
variables defined without `defvar'."
(helpful--definition 'helpful-var-without-defvar nil))
+(ert-deftest helpful-variable ()
+ "Smoke test for `helpful-variable'."
+ (helpful-variable 'tab-width))