diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | helpful.el | 36 | ||||
| -rw-r--r-- | screenshots/helpful_view_in_manual.png | bin | 0 -> 13848 bytes |
3 files changed, 38 insertions, 3 deletions
@@ -31,6 +31,11 @@ Docstrings in helpful: * Include cross-references * Hide superfluous puncuation + + +If a symbol is also documented in the Info manual, helpful will +provide a link to the relevant section too. + ### Symbol Properties  @@ -47,6 +47,7 @@ (require 's) (require 'find-func) (require 'nadvice) +(require 'info-look) (defvar-local helpful--sym nil) (defvar-local helpful--callable-p nil) @@ -213,6 +214,26 @@ This allows us to distinguish strings from symbols." 'callable-p callable-p) (buffer-string))) +(define-button-type 'helpful-manual-button + 'action #'helpful--manual + 'symbol nil + 'follow-link t + 'help-echo "Describe this symbol") + +(defun helpful--manual-button (sym) + "Return a button that shows SYM in the Info manul." + (with-temp-buffer + (insert-text-button + "View in manual" + :type 'helpful-manual-button + 'symbol sym) + (buffer-string))) + +(defun helpful--manual (button) + "Open the manual for the system that this BUTTON represents." + (let ((sym (button-get button 'symbol))) + (info-lookup 'symbol sym #'emacs-lisp-mode))) + (define-button-type 'helpful-describe-button 'action #'helpful--describe 'symbol nil @@ -319,6 +340,13 @@ If the source code cannot be found, return the sexp used." ;; TODO: offer to download C sources for current version. (indirect-function sym))) +(defun helpful--in-manual-p (sym) + "Return non-nil if SYM is in an Info manual." + (let ((completions + (info-lookup->completions 'symbol 'emacs-lisp-mode))) + (or (assoc sym completions) + (assoc-string sym completions)))) + (defun helpful--definition (sym callable-p) "Return a pair (BUF . POS) where SYM is defined." (let (buf-and-pos) @@ -534,9 +562,11 @@ state of the current symbol." (insert "\n\n")) (insert (helpful--heading "Documentation\n") - ;; TODO: a link to find this symbol in the manual, much like - ;; helpfns+ or counsel-info-lookup-symbol. - (helpful--format-docstring docstring))) + (helpful--format-docstring docstring)) + (when (helpful--in-manual-p helpful--sym) + (insert + "\n\n" + (helpful--manual-button helpful--sym)))) (when (not helpful--callable-p) (insert diff --git a/screenshots/helpful_view_in_manual.png b/screenshots/helpful_view_in_manual.png Binary files differnew file mode 100644 index 0000000..d585e08 --- /dev/null +++ b/screenshots/helpful_view_in_manual.png |
