]> git.eshelyaron.com Git - emacs.git/commitdiff
lisp/help-fns.el (help-fns--signature): Pretty print type
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 27 Mar 2025 12:59:06 +0000 (08:59 -0400)
committerEshel Yaron <me@eshelyaron.com>
Fri, 28 Mar 2025 16:17:23 +0000 (17:17 +0100)
(cherry picked from commit 0cbe17cdb6b44606cfb831358ed83cdbf22a01e3)

lisp/help-fns.el

index 78fb1b444b3af856a6a14f7140df912a44982bd8..2a2dd1f72628aa96c6611f2d48f002cb00f2bf38 100644 (file)
@@ -778,17 +778,24 @@ the C sources, too."
               (high-doc (cdr high)))
           (unless (and (symbolp function)
                        (get function 'reader-construct))
-            (insert high-usage "\n")
-            (when-let* ((gate help-display-function-type)
-                        (res (comp-function-type-spec function))
-                        (type-spec (car res))
-                        (kind (cdr res)))
-              (insert (format
-                       (if (eq kind 'inferred)
-                           "\nInferred type: %s\n"
-                         "\nDeclared type: %s\n")
-                       type-spec))))
+            (insert high-usage "\n"))
           (fill-region fill-begin (point))
+          (when-let* (help-display-function-type
+                      (res (comp-function-type-spec function))
+                      (type-spec (car res))
+                      (kind (cdr res)))
+            (insert (if (eq kind 'inferred)
+                        "\nInferred type:\n  "
+                      "\nDeclared type:\n  "))
+            (with-demoted-errors "%S"
+              (let ((beg (point)))
+                (pp type-spec (current-buffer))
+                ;; Put it on a single line if it fits.
+                (and (eql beg (+ 2 (line-beginning-position 0)))
+                     (save-excursion
+                       (forward-char -1)
+                       (<= (current-column) (- fill-column 12)))
+                     (cl--set-buffer-substring (- beg 3) beg " ")))))
           high-doc)))))
 
 (defun help-fns--parent-mode (function)