diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2018-06-29 22:46:14 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2018-06-29 22:46:14 +0100 |
| commit | bc4300efc8e429af273e7f8e45b1015500622f99 (patch) | |
| tree | 90c14fcbf2f5769f5a82db6a509dd8cdddc30bd0 | |
| parent | 35c4c17a850766401cd781ce25318ab135403e2f (diff) | |
Support pretty view of hook values too
Fixes #129
| -rw-r--r-- | CHANGELOG.md | 13 | ||||
| -rw-r--r-- | helpful.el | 36 |
2 files changed, 40 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c0f99..151b6f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ # v0.12 -Added a 'pretty view' for variables that have string or keymap -values. For strings, we show properties natively in Emacs. For -keymaps, we render each keybinding in a human-readable way along with -a link to the relevant command. +Added a 'pretty view' for string values, keymap values, and hooks. + +* For strings, we show properties natively in Emacs. + +* For keymaps, we render each keybinding in a human-readable way along +with a link to the relevant command. + +* For hooks, which are lists of functions and symbols, convert symbols + to links. # v0.11 @@ -756,6 +756,21 @@ vector suitable for `key-description', and COMMAND is a smbol." ;; Preserve the original order of the keymap. (nreverse result))))) +(defun helpful--format-hook (hook-val) + "Given a list value assigned to a hook, format it with links to functions." + (let ((lines + (--map + (if (and (symbolp it) (fboundp it)) + (helpful--button + (symbol-name it) + 'helpful-describe-exactly-button + 'symbol it + 'callable-p t) + (helpful--syntax-highlight (helpful--pretty-print it))) + hook-val))) + (format "(%s)" + (s-join "\n " lines)))) + ;; TODO: unlike `substitute-command-keys', this shows keybindings ;; which are currently shadowed (e.g. a global minor mode map). (defun helpful--format-keymap (keymap) @@ -1580,22 +1595,33 @@ state of the current symbol." (helpful--insert-section-break) (let* ((sym helpful--sym) (buf (or helpful--associated-buffer (current-buffer))) - (val (helpful--sym-value sym buf))) + (val (helpful--sym-value sym buf)) + (multiple-views-p + (or (stringp val) + (keymapp val) + (and (s-ends-with-p "-hook" (symbol-name sym)) + (consp val))))) (insert (helpful--heading "Value") (cond + (helpful--view-literal + (helpful--pretty-print val)) ;; Allow strings to be viewed with properties rendered in ;; Emacs, rather than as a literal. - ((and (stringp val) (not helpful--view-literal)) + ((stringp val) val) ;; Allow keymaps to be viewed with keybindings shown and ;; links to the commands bound. - ((and (keymapp val) (not helpful--view-literal)) + ((keymapp val) (helpful--format-keymap val)) + ((and (s-ends-with-p "-hook" (symbol-name sym)) + (consp val)) + (helpful--format-hook val)) (t - (helpful--pretty-print val))) + (error "don't know how to format value of type %s" + (type-of val)))) "\n\n") - (when (or (stringp val) (keymapp val)) + (when multiple-views-p (insert (helpful--make-toggle-literal-button) " ")) (when (memq (helpful--sym-value helpful--sym buf) '(nil t)) (insert (helpful--make-toggle-button helpful--sym buf) " ")) |
