aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2019-04-07 23:35:26 +0100
committerWilfred Hughes <me@wilfred.me.uk>2019-04-07 23:36:14 +0100
commit53ae44bd2384de5e2513496ccf6ca2fce6767299 (patch)
treec70e23568e6b4dcce1c505c246b4603419e7f005
parent9d8e7f3c3a44ac0f2bc7b0438c31226481476aff (diff)
Prefer displaying string values as literals
Fixes #200
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el48
2 files changed, 35 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1501875..b982385 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ command substitution applied inside literals.
Fixed a crash on keyboard macros in keymaps.
+String values are now shown as literals by default.
+
# v0.16
Improved wording when looking at aliases.
diff --git a/helpful.el b/helpful.el
index 9bae444..fc845f0 100644
--- a/helpful.el
+++ b/helpful.el
@@ -67,6 +67,12 @@ buffer-local variables.")
(defvar-local helpful--view-literal nil
"Whether to show a value as a literal, or a pretty interactive
view.")
+(defvar-local helpful--first-display t
+ "Whether this is the first time this results buffer has been
+displayed.
+
+Nil means that we're refreshing, so we don't want to clobber any
+settings changed by the user.")
(defgroup helpful nil
"A rich help system with contextual information."
@@ -1978,6 +1984,24 @@ may contain duplicates."
(s-ends-with-p "-functions" (symbol-name symbol)))
(consp value)))
+(defun helpful--format-value (sym value)
+ "Format VALUE as a string."
+ (cond
+ (helpful--view-literal
+ (helpful--syntax-highlight (helpful--pretty-print value)))
+ ;; Allow strings to be viewed with properties rendered in
+ ;; Emacs, rather than as a literal.
+ ((stringp value)
+ value)
+ ;; Allow keymaps to be viewed with keybindings shown and
+ ;; links to the commands bound.
+ ((keymapp value)
+ (helpful--format-keymap value))
+ ((helpful--hook-p sym value)
+ (helpful--format-hook value))
+ (t
+ (helpful--pretty-print value))))
+
(defun helpful-update ()
"Update the current *Helpful* buffer to the latest
state of the current symbol."
@@ -2034,6 +2058,13 @@ state of the current symbol."
(or (stringp val)
(keymapp val)
(helpful--hook-p sym val))))
+ (when helpful--first-display
+ (if (stringp val)
+ ;; For strings, it's more intuitive to display them as
+ ;; literals, so "1" and 1 are distinct.
+ (setq helpful--view-literal t)
+ ;; For everything else, prefer the pretty view if available.
+ (setq helpful--view-literal nil)))
(insert
(helpful--heading
(cond
@@ -2053,21 +2084,7 @@ state of the current symbol."
"Global Value")
;; This variable is not buffer-local.
(t "Value")))
- (cond
- (helpful--view-literal
- (helpful--syntax-highlight (helpful--pretty-print val)))
- ;; Allow strings to be viewed with properties rendered in
- ;; Emacs, rather than as a literal.
- ((stringp val)
- val)
- ;; Allow keymaps to be viewed with keybindings shown and
- ;; links to the commands bound.
- ((keymapp val)
- (helpful--format-keymap val))
- ((helpful--hook-p sym val)
- (helpful--format-hook val))
- (t
- (helpful--pretty-print val)))
+ (helpful--format-value sym val)
"\n\n")
(when multiple-views-p
(insert (helpful--make-toggle-literal-button) " "))
@@ -2257,6 +2274,7 @@ state of the current symbol."
(goto-char (point-min))
(forward-line (1- start-line))
(forward-char start-column)
+ (setq helpful--first-display nil)
(when opened
(kill-buffer buf))))