commit deb66c4978dd8197149e56d76b9ce3ebd72d98ed
parent 3e08b24e9eabbb17535d39b087895c04cbcd5c1f
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Fri, 3 Nov 2017 23:14:28 +0000
Show the value of buffer-local values
When creating a helpful buffer, associate it with an underlying
buffer, and look up the variable in that context. This ensures that we
show the correct value for buffer-local variables.
Fixes #50
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/helpful.el b/helpful.el
@@ -51,15 +51,20 @@
(defvar-local helpful--sym nil)
(defvar-local helpful--callable-p nil)
+(defvar-local helpful--associated-buffer nil
+ "We store a reference to the buffer we were called from, so we can
+show the value of buffer-local variables.")
(defun helpful--buffer (symbol callable-p)
"Return a buffer to show help for SYMBOL in."
- (let ((buf (get-buffer-create
+ (let ((current-buffer (current-buffer))
+ (buf (get-buffer-create
(format "*helpful: %s*" symbol))))
(with-current-buffer buf
(helpful-mode)
(setq helpful--sym symbol)
- (setq helpful--callable-p callable-p))
+ (setq helpful--callable-p callable-p)
+ (setq helpful--associated-buffer current-buffer))
buf))
(defun helpful--heading (text)
@@ -593,7 +598,11 @@ state of the current symbol."
(when (not helpful--callable-p)
(insert
(helpful--heading "\n\nValue\n")
- (helpful--pretty-print (symbol-value helpful--sym))))
+ (let ((sym helpful--sym)
+ (buf (or helpful--associated-buffer (current-buffer))))
+ (helpful--pretty-print
+ (with-current-buffer buf
+ (symbol-value sym))))))
;; Show keybindings.
;; TODO: allow users to conveniently add and remove keybindings.