diff options
| -rw-r--r-- | helpful.el | 15 | ||||
| -rw-r--r-- | test/helpful-unit-test.el | 17 |
2 files changed, 29 insertions, 3 deletions
@@ -1885,7 +1885,7 @@ OBJ may be a symbol or a compiled function object." 70 (format "%s is %s %s %s %s." (if (symbolp sym) - (format "%S" sym) + (helpful--format-symbol sym) "This lambda") (if (string-match-p (rx bos (or "a" "e" "i" "o" "u")) @@ -2354,6 +2354,14 @@ state of the current symbol." arg-str (s-upcase arg-str)))) +(defun helpful--format-symbol (sym) + "Format symbol as a string, escaping as necessary." + ;; Arguably this is an Emacs bug. We should be able to use + ;; (format "%S" sym) + ;; but that converts foo? to "foo\\?". You can see this in other + ;; parts of the Emacs UI, such as ERT. + (s-replace " " "\\ " (format "%s" sym))) + (defun helpful--signature (sym) "Get the signature for function SYM, as a string. For example, \"(some-func FOO &optional BAR)\"." @@ -2383,11 +2391,12 @@ 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)" + (helpful--format-symbol sym) (s-join " " formatted-args))) ;; Otherwise, this function takes no arguments when called. (t - (format "(%S)" sym))))) + (format "(%s)" (helpful--format-symbol sym)))))) ;; If the docstring ends with (fn FOO BAR), extract that. (-when-let (docstring (documentation sym)) diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el index 5dc0c63..14d44dc 100644 --- a/test/helpful-unit-test.el +++ b/test/helpful-unit-test.el @@ -793,6 +793,23 @@ find the source code." (should (s-starts-with-p "helpful-test-fn-interactive is an interactive function" summary)))) +(defun helpful-test-fn? () + (interactive)) + +(ert-deftest helpful--summary--fn-with-? () + "Ensure we use don't needlessly escape ? in function names." + (let* ((summary (helpful--summary 'helpful-test-fn? 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? is" summary)))) + +(ert-deftest helpful--signature-fn-with? () + "Ensure that symbols with question marks are handled correctly." + (should + (equal (helpful--signature 'helpful-test-fn?) + "(helpful-test-fn?)"))) + (defun helpful-test-fn-with\ space () 42) |
