diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2019-04-07 23:35:26 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2019-04-07 23:36:14 +0100 |
| commit | 53ae44bd2384de5e2513496ccf6ca2fce6767299 (patch) | |
| tree | c70e23568e6b4dcce1c505c246b4603419e7f005 /helpful.el | |
| parent | 9d8e7f3c3a44ac0f2bc7b0438c31226481476aff (diff) | |
Prefer displaying string values as literals
Fixes #200
Diffstat (limited to 'helpful.el')
| -rw-r--r-- | helpful.el | 48 |
1 files changed, 33 insertions, 15 deletions
@@ -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)))) |
