aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2019-01-13 18:51:47 +0000
committerWilfred Hughes <me@wilfred.me.uk>2019-01-13 18:52:34 +0000
commitcf24f963bd77f679f09057c55c6a4683b3f3a5cb (patch)
treed78015e2fc5fa688aa4dda495c2f341f1903ac37
parent751caad20387c55ae8dc3f7cfa8f638a4d2d3ad5 (diff)
Read and display symbols with spaces correctly
Fixes #172
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el14
-rw-r--r--test/helpful-unit-test.el17
3 files changed, 27 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35831fa..6b93c9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
Improved wording when looking at aliases.
+Fixed several issues for symbols that contain spaces.
+
# v0.15
Fixed a crash on formatting values.
diff --git a/helpful.el b/helpful.el
index 07d8227..be533e0 100644
--- a/helpful.el
+++ b/helpful.el
@@ -1736,7 +1736,9 @@ OBJ may be a symbol or a compiled function object."
(s-word-wrap
70
(format "%s is %s %s %s."
- (if (symbolp sym) sym "This lambda")
+ (if (symbolp sym)
+ (format "%S" sym)
+ "This lambda")
description kind defined))))
(defun helpful--callees (form)
@@ -2162,11 +2164,11 @@ For example, \"(some-func FOO &optional BAR)\"."
(s-join " " formatted-args)))
;; If it has multiple arguments, join them with spaces.
(formatted-args
- (format "(%s %s)" sym
+ (format "(%S %s)" sym
(s-join " " formatted-args)))
;; Otherwise, this function takes no arguments when called.
(t
- (format "(%s)" sym)))))
+ (format "(%S)" sym)))))
;; If the docstring ends with (fn FOO BAR), extract that.
(-when-let (docstring (documentation sym))
@@ -2230,9 +2232,9 @@ escapes that are used by `substitute-command-keys'."
(rx ": " eos)
(format " (default: %s): " default-val)
prompt)))
- (read (completing-read prompt obarray
- predicate t nil nil
- default-val))))
+ (intern (completing-read prompt obarray
+ predicate t nil nil
+ default-val))))
;;;###autoload
(defun helpful-function (symbol)
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
index 0ab830f..cff43fc 100644
--- a/test/helpful-unit-test.el
+++ b/test/helpful-unit-test.el
@@ -371,6 +371,12 @@ variables defined without `defvar'."
(equal (helpful--signature 'some-unused-function)
"(some-unused-function [Arg list not available until function definition is loaded.])")))
+(ert-deftest helpful--signature-space ()
+ "Ensure that symbols with spaces are handled correctly."
+ (should
+ (equal (helpful--signature 'helpful-test-fn-with\ space)
+ "(helpful-test-fn-with\\ space)")))
+
(ert-deftest helpful--signature--advertised ()
"Ensure that we respect functions that declare `advertised-calling-convention'."
(should
@@ -705,6 +711,17 @@ find the source code."
(should
(s-starts-with-p "if is a special form defined in" summary))))
+(defun helpful-test-fn-with\ space ()
+ 42)
+
+(ert-deftest helpful--summary--symbol-with-space ()
+ "Ensure we correctly format symbols containing spaces."
+ (let* ((summary (helpful--summary 'helpful-test-fn-with\ space t nil nil)))
+ ;; Strip properties to make assertion messages more readable.
+ (set-text-properties 0 (1- (length summary)) nil summary)
+ (should
+ (s-starts-with-p "helpful-test-fn-with\\ space is a function" summary))))
+
(ert-deftest helpful--bound-p ()
;; Functions.
(should (helpful--bound-p 'message))