emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/eldoc-eglot-rework 607d9ce43c4 2/3: Render Eldoc's echo area sep


From: João Távora
Subject: scratch/eldoc-eglot-rework 607d9ce43c4 2/3: Render Eldoc's echo area separately
Date: Thu, 23 Mar 2023 05:04:36 -0400 (EDT)

branch: scratch/eldoc-eglot-rework
commit 607d9ce43c426045026cf010228e03ebf503cf82
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--echo-area-render): New helper.
    (eldoc-display-in-echo-area): Use 'eldoc--echo-area-render'.
---
 lisp/emacs-lisp/eldoc.el | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index cbccfd46a96..f114a6d5e87 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,14 @@ 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', VALUE being a boolean indicating that
+  `eldoc-display-in-echo-area' should skip this item.
+
 Finally, major modes should modify this hook locally, for
 example:
   (add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t)
@@ -530,6 +538,23 @@ If INTERACTIVE, display it.  Else, return said buffer."
                                  ""))))))
   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 noecho do
+           (insert (if thing
+                       (concat
+                        (propertize (format "%s" thing)
+                                    'face (plist-get plist :face))
+                        ": "
+                        this-doc)
+                     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 +640,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))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]