commit 3d12b42b08215a1cb590bbfc33edd72e0156c63b
parent 6274c100b50c977ed7310d0f99eba26951b51f13
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Thu, 13 Sep 2018 00:40:36 +0100
More accurate extraction of DEFVAR source code
Diffstat:
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -1,5 +1,9 @@
# v0.14 (unreleased)
+Fixed an issue where source code of primitive variables included the
+whole surrounding function. This was less useful and significantly
+slower.
+
Fixed an issue with Remacs compatibility.
# v0.13
diff --git a/helpful.el b/helpful.el
@@ -1092,7 +1092,19 @@ If the source code cannot be found, return the sexp used."
(save-excursion
(save-restriction
(goto-char pos)
- (narrow-to-defun t)
+
+ (if (and (helpful--primitive-p sym callable-p)
+ (not callable-p))
+ ;; For variables defined in .c files, only show the
+ ;; DEFVAR expression rather than the huge containing
+ ;; function.
+ (progn
+ (setq pos (line-beginning-position))
+ (forward-list)
+ (forward-char)
+ (narrow-to-region pos (point)))
+ ;; Narrow to the top-level definition.
+ (narrow-to-defun t))
;; If there was a preceding comment, POS will be
;; after that comment. Move the position to include that comment.