From: Štěpán Němec Date: Tue, 24 May 2022 12:49:42 +0000 (+0200) Subject: Add elisp-eldoc-var-docstring-with-value function X-Git-Tag: emacs-29.0.90~1910^2~463 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8420d7cce72b7e6c69265e60c10a0ea4e420934c;p=emacs.git Add elisp-eldoc-var-docstring-with-value function * lisp/progmodes/elisp-mode.el (elisp-eldoc-var-docstring-with-value): New function (bug#55096). --- diff --git a/etc/NEWS b/etc/NEWS index 97948074411..1fa2d086b9a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1868,6 +1868,9 @@ functions. * Lisp Changes in Emacs 29.1 +--- +** New eldoc function: 'elisp-eldoc-var-docstring-with-value'. + ** 'save-some-buffers' can now be extended to save other things. Traditionally, 'save-some-buffers' saved buffers, and also saved abbrevs. This has been generalized via the diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 70826b4c3a9..84b7938bf0d 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1763,7 +1763,8 @@ Intended for `eldoc-documentation-functions' (which see)." (defun elisp-eldoc-var-docstring (callback &rest _ignored) "Document variable at point. -Intended for `eldoc-documentation-functions' (which see)." +Intended for `eldoc-documentation-functions' (which see). +Also see `elisp-eldoc-var-docstring-with-value'." (let* ((sym (elisp--current-symbol)) (docstring (and sym (elisp-get-var-docstring sym)))) (when docstring @@ -1771,6 +1772,32 @@ Intended for `eldoc-documentation-functions' (which see)." :thing sym :face 'font-lock-variable-name-face)))) +(defun elisp-eldoc-var-docstring-with-value (callback &rest _) + "Document variable at point. +Intended for `eldoc-documentation-functions' (which see). +Also see `elisp-eldoc-var-docstring-with-value'." + (when-let ((cs (elisp--current-symbol))) + (when (and (boundp cs) + ;; nil and t are boundp! + (not (null cs)) + (not (eq cs t))) + (funcall callback + (format "%.100S %s" + (symbol-value cs) + (let* ((doc (documentation-property + cs 'variable-documentation t)) + (more (- (length doc) 1000))) + (concat (propertize + (string-limit (if (string= doc "nil") + "Undocumented." + doc) + 1000) + 'face 'font-lock-doc-face) + (when (> more 0) + (format "[%sc more]" more))))) + :thing cs + :face 'font-lock-variable-name-face)))) + (defun elisp-get-fnsym-args-string (sym &optional index) "Return a string containing the parameter list of the function SYM. If SYM is a subr and no arglist is obtainable from the docstring