[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/eldoc-eglot-rework f223ca03186 2/4: Render Eldoc's echo area sep
From: |
João Távora |
Subject: |
scratch/eldoc-eglot-rework f223ca03186 2/4: Render Eldoc's echo area separately |
Date: |
Thu, 23 Mar 2023 09:57:32 -0400 (EDT) |
branch: scratch/eldoc-eglot-rework
commit f223ca031863babe5032bbc7197a04ce5e2340d9
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Render Eldoc's echo area separately
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.
* 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'.
fixup
---
lisp/emacs-lisp/eldoc.el | 108 +++++++++++++++++++++++++++++------------------
1 file changed, 66 insertions(+), 42 deletions(-)
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index cbccfd46a96..59fd2b8ab89 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
@@ -448,6 +448,16 @@ documentation-displaying frontends. For example, KEY can
be:
`eldoc-display-in-echo-area' and `eldoc-display-in-buffer' will
use when displaying `:thing''s value.
+* `:origin', VALUE being the member of
+ `eldoc-documentation-functions' where DOCSTRING
+ originated. `eldoc-display-in-buffer' may use this organize the
+ documentation buffer accordingly.
+
+* `:noecho', a non-nil VALUE indicating that
+ `eldoc-display-in-echo-area' should not present this DOCSTRING
+ fully, to save space. If a number, it is a character position
+ up to which a substring can be displayed in the echo are.
+
Finally, major modes should modify this hook locally, for
example:
(add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t)
@@ -471,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.
@@ -496,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 noecho = (plist-get plist :noecho)
+ for thing = (plist-get plist :thing)
+ unless (eq noecho t) do
+ (when noecho (setq this-doc (substring this-doc 0 noecho)))
+ (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'."
@@ -615,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))))))