commit a102f46361a41798d8f7ef429f244bb7a81a5868
parent a7d2098dfd71f948340f63bb4ba84115725529e3
Author: Nick Drozd <nicholasdrozd@gmail.com>
Date: Sun, 3 Mar 2019 21:45:49 -0600
Fix type error for unbound symbols
Diffstat:
2 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/helpful.el b/helpful.el
@@ -2426,27 +2426,25 @@ nil if SYMBOL doesn't begin with \"F\" or \"V\"."
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))
- ((let ((fsym (helpful--convert-c-name symbol nil)))
- (when (fboundp fsym)
- (helpful-callable fsym)
- fsym)))
- ((let ((vsym (helpful--convert-c-name symbol t)))
- (when (boundp vsym)
- (helpful-variable vsym)
- vsym)))
- (t
- (user-error "Not bound: %S" symbol))))
+ (let ((c-var-sym (helpful--convert-c-name symbol nil))
+ (c-fn-sym (helpful--convert-c-name symbol t)))
+ (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))
+ ((and c-fn-sym (fboundp c-fn-sym))
+ (helpful-callable c-fn-sym))
+ ((and c-var-sym (boundp c-var-sym))
+ (helpful-variable c-var-sym))
+ (t
+ (user-error "Not bound: %S" symbol)))))
;;;###autoload
(defun helpful-variable (symbol)
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
@@ -892,6 +892,13 @@ find the source code."
(should-not
(helpful--convert-c-name 'Vgc_cons_percentage nil)))
+(ert-deftest helpful-symbol-unbound ()
+ "Ensure we inform the user if we're given an unbound symbol."
+ (should
+ (condition-case _
+ (helpful-symbol 'notboundtoanything)
+ ('user-error t))))
+
(ert-deftest helpful--loads-autoload-symbol ()
"When asked to describe an autoloaded symbol, just load it."
;; This test assumes that you haven't loaded tetris.el.gz in your