Subject: 28.0.50; [PATCH] ElDoc buffer mode and separator

From: Andrii Kolomoiets <[email-masked]>
Date: Thu, 26 Nov 2020 14:42:47 +0200

Hi,

Patch attached.

The configurable separator will make it possible to show multiple docs
in user pleasant way.

The mode will allow tweak ElDoc doc buffer appearance by adding hooks.

With little customization and custom display function in
display-buffer-alist 'M-x eldoc-doc-buffer' can show the ElDoc buffer
like some kind of tooltip.  See attached screenshot.

Thanks!

>From d13320ce2126b944cb03272b5546e08251b266db Mon Sep 17 00:00:00 2001
From: Andrii Kolomoiets <[email-masked]>
Date: Thu, 26 Nov 2020 14:21:54 +0200
Subject: [PATCH] ElDoc buffer mode and separator

* lisp/emacs-lisp/eldoc.el (eldoc-doc-buffer-separator): New option.
(eldoc-doc-mode-map): New keymap.
(eldoc-doc-mode): New mode.
(eldoc--format-doc-buffer): Use them.
---
 lisp/emacs-lisp/eldoc.el | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 78cb8f08c3..e2c8d001d6 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -129,6 +129,11 @@ eldoc-echo-area-prefer-doc-buffer
 is only skipped if the documentation doesn't fit there."
   :type 'boolean)

+(defcustom eldoc-doc-buffer-separator "\n"
+  "String used by Eldoc to separate docs in the ElDoc documentation buffer."
+  :type 'string
+  :version "28.1")
+
 (defface eldoc-highlight-function-argument
   '((t (:inherit bold)))
   "Face used for the argument at point in a function's argument list.
@@ -465,6 +470,24 @@ eldoc-doc-buffer
                                              (buffer-name)))
     (display-buffer (current-buffer))))

+(defvar eldoc-doc-mode-map
+  (let ((map (make-sparse-keymap)))
+    (suppress-keymap map)
+    (define-key map "q" 'quit-window)
+    (define-key map " " 'scroll-up-command)
+    (define-key map [?\S-\ ] 'scroll-down-command)
+    (define-key map "\C-?" 'scroll-down-command)
+    (define-key map "?" 'describe-mode)
+    (define-key map "h" 'describe-mode)
+    (define-key map ">" 'end-of-buffer)
+    (define-key map "<" 'beginning-of-buffer)
+    map)
+  "Keymap used in ElDoc documentation buffer.")
+
+(define-derived-mode eldoc-doc-mode fundamental-mode "ElDoc doc"
+  "Major mode for ElDoc documentation buffer."
+  (setq buffer-read-only t))
+
 (defun eldoc--format-doc-buffer (docs)
   "Ensure DOCS are displayed in an *eldoc* buffer."
   (interactive (list t))
@@ -472,12 +495,13 @@ eldoc--format-doc-buffer
                            eldoc--doc-buffer
                          (setq eldoc--doc-buffer
                                (get-buffer-create " *eldoc*")))
+    (unless (eq major-mode 'eldoc-doc-mode)
+      (eldoc-doc-mode))
     (unless (eq docs eldoc--doc-buffer-docs)
       (setq-local eldoc--doc-buffer-docs docs)
       (let ((inhibit-read-only t)
             (things-reported-on))
-        (erase-buffer) (setq buffer-read-only t)
-        (local-set-key "q" 'quit-window)
+        (erase-buffer)
         (cl-loop for (docs . rest) on docs
                  for (this-doc . plist) = docs
                  for thing = (plist-get plist :thing)
@@ -490,7 +514,7 @@ eldoc--format-doc-buffer
                         ": "
                         this-doc))
                  do (insert this-doc)
-                 when rest do (insert "\n")
+                 when rest do (insert eldoc-doc-buffer-separator)
                  finally (goto-char (point-min)))
         ;; Rename the buffer, taking into account whether it was
         ;; hidden or not
--
2.15.1