[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master e19994fe8c0 4/7: ElDoc: rework rendering of echo area (bug#62029)
From: |
João Távora |
Subject: |
master e19994fe8c0 4/7: ElDoc: rework rendering of echo area (bug#62029) |
Date: |
Thu, 23 Mar 2023 17:17:42 -0400 (EDT) |
branch: master
commit e19994fe8c000b0ed2dbc667cdec26cf54356907
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
ElDoc: rework rendering of echo area (bug#62029)
Previously, the display function 'eldoc-display-in-echo-area' reused
the same buffer as 'eldoc-display-in-doc-buffer', but that made it
harder to render documentation items differently depending on the
specific constraints of each display functions.
Allow documentation-generating backends to pass an :echo-area property
for tweaking the echo area display of certain documentation items.
* lisp/emacs-lisp/eldoc.el (eldoc-documentation-functions): Update
docstring.
(eldoc--doc-buffer-docs): Remove.
(eldoc--format-doc-buffer): Simplify.
(eldoc--echo-area-render): New helper.
(eldoc-display-in-echo-area): Use 'eldoc--echo-area-render'.
---
lisp/emacs-lisp/eldoc.el | 103 ++++++++++++++++++++++++++++-------------------
1 file changed, 61 insertions(+), 42 deletions(-)
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 8fc109dcfef..2108e189fbd 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -437,7 +437,7 @@ documentation-producing backend to cooperate with specific
documentation-displaying frontends. For example, KEY can be:
* `:thing', VALUE being a short string or symbol designating what
- is being reported on. It can, for example be the name of the
+ DOCSTRING reports on. It can, for example be the name of the
function whose signature is being documented, or the name of
the variable whose docstring is being documented.
`eldoc-display-in-echo-area', a member of
@@ -453,6 +453,11 @@ documentation-displaying frontends. For example, KEY can
be:
originated. `eldoc-display-in-buffer' may use this organize the
documentation buffer accordingly.
+* `:echo', controlling how `eldoc-display-in-echo-area' should
+ present this documentation item, to save space. If VALUE is
+ `skip' don't echo DOCSTRING. If a number, only echo DOCSTRING
+ up to that character position.
+
Finally, major modes should modify this hook locally, for
example:
(add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t)
@@ -476,8 +481,6 @@ directly from the user or from ElDoc's automatic
mechanisms'.")
(defvar eldoc--doc-buffer nil "Buffer displaying latest ElDoc-produced docs.")
-(defvar eldoc--doc-buffer-docs nil "Documentation items in
`eldoc--doc-buffer'.")
-
(defun eldoc-doc-buffer (&optional interactive)
"Get or display ElDoc documentation buffer.
@@ -501,40 +504,56 @@ If INTERACTIVE, display it. Else, return said buffer."
eldoc--doc-buffer
(setq eldoc--doc-buffer
(get-buffer-create " *eldoc*")))
- (unless (eq docs eldoc--doc-buffer-docs)
- (setq-local eldoc--doc-buffer-docs docs)
- (let ((inhibit-read-only t)
- (things-reported-on))
- (special-mode)
- (erase-buffer)
- (setq-local nobreak-char-display nil)
- (cl-loop for (docs . rest) on docs
- for (this-doc . plist) = docs
- for thing = (plist-get plist :thing)
- when thing do
- (cl-pushnew thing things-reported-on)
- (setq this-doc
- (concat
- (propertize (format "%s" thing)
- 'face (plist-get plist :face))
- ": "
- this-doc))
- do (insert this-doc)
- when rest do (insert "\n")
- finally (goto-char (point-min)))
- ;; Rename the buffer, taking into account whether it was
- ;; hidden or not
- (rename-buffer (format "%s*eldoc%s*"
- (if (string-match "^ " (buffer-name)) " " "")
- (if things-reported-on
- (format " for %s"
- (mapconcat
- (lambda (s) (format "%s" s))
- things-reported-on
- ", "))
- ""))))))
+ (let ((inhibit-read-only t)
+ (things-reported-on))
+ (special-mode)
+ (erase-buffer)
+ (setq-local nobreak-char-display nil)
+ (cl-loop for (docs . rest) on docs
+ for (this-doc . plist) = docs
+ for thing = (plist-get plist :thing)
+ when thing do
+ (cl-pushnew thing things-reported-on)
+ (setq this-doc
+ (concat
+ (propertize (format "%s" thing)
+ 'face (plist-get plist :face))
+ ": "
+ this-doc))
+ do (insert this-doc)
+ when rest do (insert "\n")
+ finally (goto-char (point-min)))
+ ;; Rename the buffer, taking into account whether it was
+ ;; hidden or not
+ (rename-buffer (format "%s*eldoc%s*"
+ (if (string-match "^ " (buffer-name)) " " "")
+ (if things-reported-on
+ (format " for %s"
+ (mapconcat
+ (lambda (s) (format "%s" s))
+ things-reported-on
+ ", "))
+ "")))))
eldoc--doc-buffer)
+(defun eldoc--echo-area-render (docs)
+ "Similar to `eldoc--format-doc-buffer', but for echo area.
+Helper for `eldoc-display-in-echo-area'."
+ (cl-loop for (item . rest) on docs
+ for (this-doc . plist) = item
+ for echo = (plist-get plist :echo)
+ for thing = (plist-get plist :thing)
+ unless (eq echo 'skip) do
+ (when echo (setq this-doc (substring this-doc 0 echo)))
+ (when thing (setq this-doc
+ (concat
+ (propertize (format "%s" thing)
+ 'face (plist-get plist :face))
+ ": "
+ this-doc)))
+ (insert this-doc)
+ (when rest (insert "\n"))))
+
(defun eldoc--echo-area-substring (available)
"Given AVAILABLE lines, get buffer substring to display in echo area.
Helper for `eldoc-display-in-echo-area'."
@@ -620,15 +639,15 @@ Honor `eldoc-echo-area-use-multiline-p' and
single-doc)
((and (numberp available)
(cl-plusp available))
- ;; Else, given a positive number of logical lines, we
- ;; format the *eldoc* buffer, using as most of its
- ;; contents as we know will fit.
- (with-current-buffer (eldoc--format-doc-buffer docs)
- (save-excursion
- (eldoc--echo-area-substring available))))
+ ;; Else, given a positive number of logical lines, grab
+ ;; as many as we can.
+ (with-temp-buffer
+ (eldoc--echo-area-render docs)
+ (eldoc--echo-area-substring available)))
(t ;; this is the "truncate brutally" situation
(let ((string
- (with-current-buffer (eldoc--format-doc-buffer docs)
+ (with-temp-buffer
+ (eldoc--echo-area-render docs)
(buffer-substring (goto-char (point-min))
(progn (end-of-visible-line)
(point))))))
- master updated (b19d040a4fe -> 4566a0c6b82), João Távora, 2023/03/23
- master 9b18407c7fd 3/7: ElDoc: remember origin backend in doc snippets (bug#62029), João Távora, 2023/03/23
- master e19994fe8c0 4/7: ElDoc: rework rendering of echo area (bug#62029),
João Távora <=
- master 0effdb29d6d 2/7: Eglot: rework progress indicators, João Távora, 2023/03/23
- master f20fe3e11a9 1/7: Eglot: more leniently handle 'window/showMessageRequest', João Távora, 2023/03/23
- master 67c1e6e89ce 5/7: Eglot: inform ElDoc about overly long 'hover' docs, João Távora, 2023/03/23
- master fe8af4eb30b 6/7: Eglot: don't send invisible text to Eldoc, João Távora, 2023/03/23
- master 4566a0c6b82 7/7: Eglot: let user opt-in to plaintext LSP docs (bug#61373), João Távora, 2023/03/23