helpful

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

commit 4cf4381aca731db2f9473cc39c64413ddedcde63
parent 2d23a267b316adcd7754ab1fbb4154b9cb2bfbcb
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 16 Feb 2019 18:17:25 +0000

Smarter buffer prompt when inspecting buffer-local values

See discussion in #49

Diffstat:
MCHANGELOG.md | 3+++
Mhelpful.el | 42++++++++++++++++++++++++++++++++++--------
2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,9 @@ Fixed several issues for symbols that contain spaces. Fixed an issue when viewing `inhibit-read-only`. +Improved the buffer prompt to be more relevant when inspecting +buffer-local values. + # v0.15 Fixed a crash on formatting values. diff --git a/helpful.el b/helpful.el @@ -60,8 +60,10 @@ (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.") + "The buffer being used when showing inspecting +buffer-local variables.") +(defvar-local helpful--start-buffer nil + "The buffer we were originally called from.") (defvar-local helpful--view-literal nil "Whether to show a value as a literal, or a pretty interactive view.") @@ -141,6 +143,7 @@ can make Helpful very slow.") (helpful-mode) (setq helpful--sym symbol) (setq helpful--callable-p callable-p) + (setq helpful--start-buffer current-buffer) (setq helpful--associated-buffer current-buffer)) buf)) @@ -509,12 +512,35 @@ If narrowing is in effect, widen if POS isn't in the narrowed area." This is largely equivalent to `read-buffer', but counsel.el overrides that to include previously opened buffers." - (get-buffer - (completing-read - prompt - (-map #'buffer-name (buffer-list)) - predicate - t))) + (let* ((names (-map #'buffer-name (buffer-list))) + (default + (cond + ;; If we're already looking at a buffer-local value, start + ;; the prompt from the relevant buffer. + ((and helpful--associated-buffer + (buffer-live-p helpful--associated-buffer)) + (buffer-name helpful--associated-buffer)) + ;; If we're looking at the global value, offer the initial + ;; buffer. + ((and helpful--start-buffer + (buffer-live-p helpful--start-buffer)) + (buffer-name helpful--start-buffer)) + ;; If we're looking at the global value and have no initial + ;; buffer, choose the first normal buffer. + (t + (--first (and (not (s-starts-with-p " " it)) + (not (s-starts-with-p "*" it))) + names)) + ))) + (get-buffer + (completing-read + prompt + names + predicate + t + nil + nil + default)))) (defun helpful--associated-buffer (button) "Change the associated buffer, so we can see buffer-local values."