Add elisp-eldoc-var-docstring-with-value function

* lisp/progmodes/elisp-mode.el
(elisp-eldoc-var-docstring-with-value): New function (bug#55096).
This commit is contained in:
Štěpán Němec 2022-05-24 14:49:42 +02:00 committed by Lars Ingebrigtsen
parent 388e0c18f4
commit 8420d7cce7
2 changed files with 31 additions and 1 deletions

View file

@ -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

View file

@ -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