aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-09-24 14:03:35 +0100
committerWilfred Hughes <me@wilfred.me.uk>2017-09-24 14:03:35 +0100
commitb9a06978b6ffcd7f0ea213a6f534fa39318f0050 (patch)
treee0c205f469b9e9c71a538719b8cb72b5d1627289
parenta6113f9c48132573b35cc88f141f4bd9f08e3b7d (diff)
Define a helpful-symbol command0.2
-rw-r--r--CHANGELOG.md4
-rw-r--r--helpful.el31
2 files changed, 32 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a757de..0e09877 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/helpful.el b/helpful.el
index 5d1ee6e..744b590 100644
--- a/helpful.el
+++ b/helpful.el
@@ -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."
@@ -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."