commit 23dc24816ffb2c7bc55e64ad2dc8a720bd0b2716
parent dfbcae90bcca7de1428848f3397a7b0b2b663ffc
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Sun, 10 Dec 2017 12:51:44 +0000
Better handling of special forms
Ensure the buffer name is correct, and update the helpful-callable
docstrings to mention special forms too.
Don't offer to forget special forms -- this will probably break your
Emacs instance.
Diffstat:
3 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -5,6 +5,9 @@ toggled. If a variable is a `defcustom`, we also offer Customize.
Show the name of variables at the top of the helpful buffer.
+Improved handling of special forms, and prevent users from
+accidentally unbinding special forms.
+
# v0.3
Fixed a crash on autoloaded functions that aren't loaded yet.
diff --git a/helpful.el b/helpful.el
@@ -63,7 +63,8 @@ show the value of buffer-local variables.")
((not callable-p) "variable")
((commandp symbol) "command")
((macrop symbol) "macro")
- ((functionp symbol) "function")))
+ ((functionp symbol) "function")
+ ((special-form-p symbol) "special form")))
(defun helpful--buffer (symbol callable-p)
"Return a buffer to show help for SYMBOL in."
@@ -138,10 +139,7 @@ This allows us to distinguish strings from symbols."
"Unbind the current symbol."
(let* ((sym (button-get button 'symbol))
(callable-p (button-get button 'callable-p))
- (kind (cond
- ((not callable-p) "variable")
- ((functionp sym) "function")
- (t "macro"))))
+ (kind (helpful--kind-name sym callable-p)))
(when (yes-or-no-p (format "Forget %s %s?" kind sym))
(if callable-p
(fmakunbound sym)
@@ -715,13 +713,17 @@ state of the current symbol."
nil
:type 'helpful-disassemble-button
'symbol helpful--sym)
- " "))
- (make-text-button
- "Forget" nil
- :type 'helpful-forget-button
- 'symbol helpful--sym
- 'callable-p helpful--callable-p)
+ " ")))
+ (unless (special-form-p helpful--sym)
+ (insert
+ " "
+ (make-text-button
+ "Forget" nil
+ :type 'helpful-forget-button
+ 'symbol helpful--sym
+ 'callable-p helpful--callable-p)))
+ (insert
(helpful--heading "\n\nSource Code\n")
(cond
(source-path
@@ -866,11 +868,11 @@ For example, \"(some-func FOO &optional BAR)\"."
;;;###autoload
(defun helpful-callable (symbol)
- "Show help for function or macro named SYMBOL.
+ "Show help for function, macro or special form named SYMBOL.
See also `helpful-macro' and `helpful-function'."
(interactive
- (list (helpful--read-symbol "Function/macro: " #'fboundp)))
+ (list (helpful--read-symbol "Callable: " #'fboundp)))
(pop-to-buffer (helpful--buffer symbol t))
(helpful-update))
diff --git a/test/unit-test.el b/test/unit-test.el
@@ -135,3 +135,17 @@ buffers lying around."
(should
(null
(-difference (buffer-list) expected-buffers)))))
+
+(ert-deftest helpful--kind-name ()
+ (should
+ (equal
+ (helpful--kind-name 'message nil)
+ "variable"))
+ (should
+ (equal
+ (helpful--kind-name 'message t)
+ "function"))
+ (should
+ (equal
+ (helpful--kind-name 'save-excursion t)
+ "special form")))