From: Elías Gabriel Pérez Date: Tue, 8 Apr 2025 05:00:20 +0000 (-0600) Subject: Add variable for control docstring length in elisp eldoc functions X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5ff2c18f41eb16df6c2e0b1ad4e3552cff31c4d8;p=emacs.git Add variable for control docstring length in elisp eldoc functions * 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) --- diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 44be5acd8c4..9eb50ad7f22 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -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)))))