emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] emacs-25 d0d9f55: Allow newlines inside cl function ar


From: Dmitry Gutov
Subject: Re: [Emacs-diffs] emacs-25 d0d9f55: Allow newlines inside cl function arglists
Date: Tue, 10 May 2016 13:11:05 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1

On 05/10/2016 04:34 AM, Stefan Monnier wrote:

Why?

Because nobody has proposed a better patch until now.

This is problematic since it might be difficult to adjust
help-split-fundoc correspondingly.

We already have this problem with e.g.

  (cl-defgeneric asdasd (&optional (separator "\n")))

because when that is evaluated, ARGLIST passed to help-add-fundoc-usage is a form, not a string. I think it's better than not being able to define the function at all.

We could escape the newlines in the returned string. What's the best place to do that? Do we have a handier function that turns "\n" into "\\n", and does the same for \r, \t, and maybe unprintable characters?

This seems to work:

diff --git a/lisp/help.el b/lisp/help.el
index 7289375..4bd9cc1 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1394,11 +1394,14 @@ help-add-fundoc-usage
            (if (string-match "\n?\n\\'" docstring)
                (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
              "\n\n")
-           (if (stringp arglist)
- (if (string-match "\\`[^ ]+\\(\\(?:.\\|\n\\)*\\))\\'" arglist)
-                    (concat "(fn" (match-string 1 arglist) ")")
-                  (error "Unrecognized usage format"))
-             (help--make-usage-docstring 'fn arglist)))))
+            (replace-regexp-in-string
+             "\n" "\\n"
+             (if (stringp arglist)
+ (if (string-match "\\`[^ ]+\\(\\(?:.\\|\n\\)*\\))\\'" arglist)
+                     (concat "(fn" (match-string 1 arglist) ")")
+                   (error "Unrecognized usage format"))
+               (help--make-usage-docstring 'fn arglist))
+             t t))))

 (defun help-function-arglist (def &optional preserve-names)
   "Return a formal argument list for the function DEF.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]