]> git.eshelyaron.com Git - emacs.git/commitdiff
Add variable for control docstring length in elisp eldoc functions
authorElías Gabriel Pérez <eg642616@gmail.com>
Tue, 8 Apr 2025 05:00:20 +0000 (23:00 -0600)
committerEshel Yaron <me@eshelyaron.com>
Sun, 13 Apr 2025 21:00:10 +0000 (23:00 +0200)
* etc/NEWS: Announce new variable.
* lisp/progmodes/elisp-mode.el (elisp-eldoc-docstring-length-limit):
New user option.
(elisp-eldoc-funcall-with-docstring): Add "Undocumented" as
docstring if the function has no docstring.
(elisp-eldoc-var-docstring-with-value): Use
`elisp-eldoc-docstring-length-limit'.  (Bug#77628)

(cherry picked from commit 53bd9f54c61d5edac8b04cc6b72aadb48466110e)

lisp/progmodes/elisp-mode.el

index 44be5acd8c4d3a69b07853fe5c38686a66e57f8a..9eb50ad7f22b99a83a33ed5f05889b9a41eafbb2 100644 (file)
@@ -1921,6 +1921,12 @@ Intended for `eldoc-documentation-functions' (which see)."
                          'font-lock-function-name-face
                        'font-lock-keyword-face)))))
 
+(defcustom elisp-eldoc-docstring-length-limit 1000
+  "Maximum docstring character limit displayed by elisp eldoc functions."
+  :type 'natnum
+  :group 'elisp
+  :version "31.1")
+
 (defcustom elisp-eldoc-funcall-with-docstring-length 'short
   "Control length of doc string shown by `elisp-eldoc-funcall-with-docstring'.
 If set to `short', only show the first sentence of the doc string.
@@ -1937,21 +1943,26 @@ Intended for `eldoc-documentation-functions' (which see).
 Compared to `elisp-eldoc-funcall', this also includes the
 current function doc string, doc string length depends on
 `elisp-eldoc-funcall-with-docstring-length'."
-  (let* ((sym-info (elisp--fnsym-in-current-sexp))
-         (fn-sym (car sym-info))
-         (doc (when (fboundp fn-sym)
-                (propertize
-                 (cdr (help-split-fundoc
-                       (condition-case nil (documentation fn-sym t)
-                         (invalid-function nil))
-                       fn-sym))
-                 'face 'font-lock-doc-face))))
-    (when fn-sym
-      (funcall callback
+  (when-let* ((sym-info (elisp--fnsym-in-current-sexp))
+              (fn-sym (car sym-info))
+              ((fboundp fn-sym))
+              (fn-doc (or (cdr (help-split-fundoc
+                                (condition-case nil (documentation fn-sym t)
+                                  (invalid-function nil))
+                                fn-sym))
+                          "Undocumented."))
+              (more (- (length fn-doc) elisp-eldoc-docstring-length-limit))
+              (doc (concat
+                      (propertize
+                       (string-limit fn-doc elisp-eldoc-docstring-length-limit)
+                       'face 'font-lock-doc-face)
+                      (when (> more 0)
+                        (format "[%sc more]" more)))))
+    (funcall callback
                (concat (apply #'elisp-get-fnsym-args-string sym-info)
                        ;; Ensure not display the docstring in the
                        ;; mode-line.
-                       (when (and doc (not (minibufferp)))
+                       (when (not (minibufferp))
                          (concat
                           "\n"
                           (pcase elisp-eldoc-funcall-with-docstring-length
@@ -1963,7 +1974,7 @@ current function doc string, doc string length depends on
                :thing fn-sym
                :face (if (functionp fn-sym)
                          'font-lock-function-name-face
-                       'font-lock-keyword-face)))))
+                       'font-lock-keyword-face))))
 
 (defun elisp-eldoc-var-docstring (callback &rest _ignored)
   "Document variable at point by calling CALLBACK.
@@ -1991,12 +2002,12 @@ current variable value and a bigger chunk of the docstring."
                       (symbol-value cs)
                       (let* ((doc (documentation-property
                                     cs 'variable-documentation t))
-                             (more (- (length doc) 1000)))
+                             (more (- (length doc) elisp-eldoc-docstring-length-limit)))
                         (concat (propertize
                                  (string-limit (if (string= doc "nil")
                                                    "Undocumented."
                                                  doc)
-                                               1000)
+                                               elisp-eldoc-docstring-length-limit)
                                  'face 'font-lock-doc-face)
                                 (when (> more 0)
                                   (format "[%sc more]" more)))))