diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2019-02-16 18:17:25 +0000 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2019-02-16 18:18:05 +0000 |
| commit | 4cf4381aca731db2f9473cc39c64413ddedcde63 (patch) | |
| tree | 9d20f12f45912f6f1ae73526ad6700f5ce38f30b | |
| parent | 2d23a267b316adcd7754ab1fbb4154b9cb2bfbcb (diff) | |
Smarter buffer prompt when inspecting buffer-local values
See discussion in #49
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | helpful.el | 42 |
2 files changed, 37 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3f402..3d6a542 100644 --- 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. @@ -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." |
