helpful

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

commit bc4300efc8e429af273e7f8e45b1015500622f99
parent 35c4c17a850766401cd781ce25318ab135403e2f
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Fri, 29 Jun 2018 22:46:14 +0100

Support pretty view of hook values too

Fixes #129

Diffstat:
MCHANGELOG.md | 13+++++++++----
Mhelpful.el | 36+++++++++++++++++++++++++++++++-----
2 files changed, 40 insertions(+), 9 deletions(-)

diff --git 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 diff --git a/helpful.el b/helpful.el @@ -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) " "))