Skip to content

Commit

Permalink
Add a link to the manual, if this symbol is documented
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
Wilfred committed Sep 5, 2017
1 parent bb4df37 commit 2053fd4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Docstrings in helpful:
* Include cross-references
* Hide superfluous puncuation

![screenshot](screenshots/helpful_view_in_manual.png)

If a symbol is also documented in the Info manual, helpful will
provide a link to the relevant section too.

### Symbol Properties

![screenshot](screenshots/helpful_props.png)
Expand Down
36 changes: 33 additions & 3 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Binary file added screenshots/helpful_view_in_manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2053fd4

Please sign in to comment.