Skip to content

Commit

Permalink
Define a helpful-symbol command
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Sep 24, 2017
1 parent a6113f9 commit b9a0697
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ functions. This should be a drop-in replacement for
Added a command `helpful-key`, which offers help on keybindings much
like `describe-key`.

Added a command `helpful-symbol`, which offers help on variables,
functions and macros. It prompts the user if a symbol is both a
variable and a callable.

# v0.1

First release.
31 changes: 28 additions & 3 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ This allows us to distinguish strings from symbols."
(defun helpful--describe (button)
"Describe the symbol that this BUTTON represents."
(let ((sym (button-get button 'symbol)))
(if (fboundp sym)
(helpful-function sym)
(helpful-variable sym))))
(helpful-symbol sym)))

(defun helpful--describe-button (sym)
"Return a button that describes SYM."
Expand Down Expand Up @@ -780,6 +778,33 @@ See also `helpful-macro' and `helpful-function'."
(not (eq symbol nil))
(not (eq symbol t)))))

(defun helpful--bound-p (symbol)
"Return non-nil if SYMBOL is a variable or callable.
This differs from `boundp' because we do not consider nil, t
or :foo."
(or (fboundp symbol)
(helpful--variable-p symbol)))

;;;###autoload
(defun helpful-symbol (symbol)
"Show help for SYMBOL, a variable, function or macro.
See also `helpful-callable' and `helpful-variable'."
(interactive
(list (helpful--read-symbol "Symbol: " #'helpful--bound-p)))
(cond
((and (boundp symbol) (fboundp symbol))
(if (y-or-n-p
(format "%s is a both a variable and a callable, show variable?"
symbol))
(helpful-variable symbol)
(helpful-callable symbol)))
((fboundp symbol)
(helpful-callable symbol))
((boundp symbol)
(helpful-variable symbol))))

;;;###autoload
(defun helpful-variable (symbol)
"Show help for variable named SYMBOL."
Expand Down

0 comments on commit b9a0697

Please sign in to comment.