Improvements to apropos and describe-symbol

Patch the apropos button types so they call helpful instead of the
built-in describe functions.  Also add some bindings to apropos-mode-map
so it behaves like other help modes.

Add `doom/describe-symbol` function, which shows documentation for
callable and variable symbols.  If a symbol is both a variable and a
callable, it dispatches to apropos.  This gives a better workflow than
`helpful-symbol`, which annoyingly prompts the user.

Remap `describe-symbol` to `doom/describe-symbol`, and update
`+emacs-lisp-lookup-documentation` to call it also.
This commit is contained in:
Andrew Whatson 2019-03-12 14:21:41 +10:00
parent 3f282829bf
commit 7b4afa32e4
4 changed files with 45 additions and 8 deletions

View file

@ -296,6 +296,21 @@ If prefix arg is prsent, refresh the cache."
(insert "\n" indent)) (insert "\n" indent))
(delete-char -1))))))) (delete-char -1)))))))
;;;###autoload
(defun doom/describe-symbol (symbol)
"Show help for SYMBOL, a variable, function or macro."
(interactive
(list (helpful--read-symbol "Symbol: " #'helpful--bound-p)))
(let* ((sym (intern-soft symbol))
(bound (boundp sym))
(fbound (fboundp sym)))
(cond ((and sym bound (not fbound))
(helpful-variable sym))
((and sym fbound (not bound))
(helpful-callable sym))
((apropos (format "^%s\$" symbol)))
((apropos (format "%s" symbol))))))
;;;###autoload ;;;###autoload
(defun doom/what-face (arg &optional pos) (defun doom/what-face (arg &optional pos)
"Shows all faces and overlay faces at point. "Shows all faces and overlay faces at point.

View file

@ -271,13 +271,31 @@ savehist file."
;; `helpful' --- a better *help* buffer ;; `helpful' --- a better *help* buffer
(def-package! helpful (def-package! helpful
:defer t :commands (helpful-callable
helpful-command
helpful-variable
helpful-key
helpful--read-symbol)
:init :init
(define-key! (define-key!
[remap describe-function] #'helpful-callable [remap describe-function] #'helpful-callable
[remap describe-command] #'helpful-command [remap describe-command] #'helpful-command
[remap describe-variable] #'helpful-variable [remap describe-variable] #'helpful-variable
[remap describe-key] #'helpful-key)) [remap describe-key] #'helpful-key
[remap describe-symbol] #'doom/describe-symbol)
(after! apropos
;; patch apropos buttons to call helpful instead of help
(dolist (fun-bt '(apropos-function apropos-macro apropos-command))
(button-type-put
fun-bt 'action
(lambda (button)
(helpful-callable (button-get button 'apropos-symbol)))))
(dolist (var-bt '(apropos-variable apropos-user-option))
(button-type-put
var-bt 'action
(lambda (button)
(helpful-variable (button-get button 'apropos-symbol)))))))
(def-package! ws-butler (def-package! ws-butler

View file

@ -320,6 +320,11 @@
(:after helpful-mode (:after helpful-mode
:map helpful-mode-map :map helpful-mode-map
"o" #'ace-link-help) "o" #'ace-link-help)
(:after apropos
:map apropos-mode-map
"o" #'ace-link-help
"n" #'forward-button
"p" #'backward-button)
(:after info (:after info
:map Info-mode-map :map Info-mode-map
"o" #'ace-link-info) "o" #'ace-link-info)

View file

@ -126,9 +126,8 @@ library/userland functions"
;;;###autoload ;;;###autoload
(defun +emacs-lisp-lookup-documentation (thing) (defun +emacs-lisp-lookup-documentation (thing)
"Lookup THING with `helpful-symbol' if it's a symbol, apropos otherwise." "Lookup THING with `helpful-variable' if it's a variable, `helpful-callable'
(cond ((not thing) if it's callable, `apropos' otherwise."
(call-interactively #'helpful-symbol)) (if (not thing)
((if-let* ((sym (intern-soft thing))) (helpful-symbol sym))) (call-interactively #'doom/describe-symbol)
((apropos (format "^%s" thing))) (doom/describe-symbol thing)))
((apropos thing))))