[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 8420d7cce7 1/2: Add elisp-eldoc-var-docstring-with-value function
From: |
Lars Ingebrigtsen |
Subject: |
master 8420d7cce7 1/2: Add elisp-eldoc-var-docstring-with-value function |
Date: |
Tue, 24 May 2022 08:55:09 -0400 (EDT) |
branch: master
commit 8420d7cce72b7e6c69265e60c10a0ea4e420934c
Author: Štěpán Němec <stepnem@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add elisp-eldoc-var-docstring-with-value function
* lisp/progmodes/elisp-mode.el
(elisp-eldoc-var-docstring-with-value): New function (bug#55096).
---
etc/NEWS | 3 +++
lisp/progmodes/elisp-mode.el | 29 ++++++++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 9794807441..1fa2d086b9 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 70826b4c3a..84b7938bf0 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