Subject: eldoc.el: Allow custom separator between documentations in the echo area

From: Mathieu Marques <[email-masked]>
Date: Fri, 12 Mar 2021 20:10:17 +0100

Hello,

While trying out eglot.el, I played around with eldoc.el and needed to
display all pieces of documentations in the echo area at once. The joined
patch allows for a custom separator between said documentations.

First patch is a fix to indenting levels as well as untabifying the whole
file. That was done automatically by my configuration and given the
existing code I thought it would be beneficial to most to provide a patch
for that as well. Feel free to dismiss it if needed.

The second patch is the subject of this very email. With the updated code,
in the user configuration, one can customize the separator to `"\n"` and
its face to `((t :inherit shadow :strike-through t))` in order to have a
horizontal line between documentations in the echo area for instance.

I've tried following conventions described over at gnu.org, do let me know
if I've missed anything.

Best regards

-- 
Mathieu Marques
From 63d8a5f88d5a23cb2df215125e81ac78dd0d7e6a Mon Sep 17 00:00:00 2001
From: Mathieu Marques <[email-masked]>
Date: Fri, 12 Mar 2021 19:43:10 +0100
Subject: [PATCH 1/2] * lisp/emacs-lisp/eldoc.el: Untabify and fix indent
 levels

---
 lisp/emacs-lisp/eldoc.el | 58 ++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index a02406a7b7..485ea26379 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -87,7 +87,7 @@ returns another string is acceptable.
 Note that this variable has no effect, unless
 `eldoc-documentation-strategy' handles it explicitly."
   :type '(radio (function-item upcase)
-		(function-item downcase)
+                (function-item downcase)
                 function))
 (make-obsolete-variable 'eldoc-argument-case nil "25.1")
 
@@ -183,12 +183,12 @@ It should receive the same arguments as `message'.")
 When `eldoc-print-after-edit' is non-nil, ElDoc messages are only
 printed after commands contained in this obarray."
   (let ((cmds (make-vector 31 0))
-	(re (regexp-opt '("delete" "insert" "edit" "electric" "newline"))))
+        (re (regexp-opt '("delete" "insert" "edit" "electric" "newline"))))
     (mapatoms (lambda (s)
-		(and (commandp s)
-		     (string-match-p re (symbol-name s))
-		     (intern (symbol-name s) cmds)))
-	      obarray)
+                (and (commandp s)
+                     (string-match-p re (symbol-name s))
+                     (intern (symbol-name s) cmds)))
+              obarray)
     cmds))
 
 
@@ -269,8 +269,8 @@ reflect the change."
            (memq eldoc-timer timer-idle-list)) ;FIXME: Why?
       (setq eldoc-timer
             (run-with-idle-timer
-	     eldoc-idle-delay nil
-	     (lambda ()
+             eldoc-idle-delay nil
+             (lambda ()
                (when (or eldoc-mode
                          (and global-eldoc-mode
                               (eldoc--supported-p)))
@@ -291,23 +291,23 @@ reflect the change."
 Otherwise work like `message'."
   (if (minibufferp)
       (progn
-	(add-hook 'minibuffer-exit-hook
-		  (lambda () (setq eldoc-mode-line-string nil
-			      ;; https://debbugs.gnu.org/16920
-			      eldoc-last-message nil))
-		  nil t)
-	(with-current-buffer
-	    (window-buffer
-	     (or (window-in-direction 'above (minibuffer-window))
-		 (minibuffer-selected-window)
-		 (get-largest-window)))
+        (add-hook 'minibuffer-exit-hook
+                  (lambda () (setq eldoc-mode-line-string nil
+                                   ;; https://debbugs.gnu.org/16920
+                                   eldoc-last-message nil))
+                  nil t)
+        (with-current-buffer
+            (window-buffer
+             (or (window-in-direction 'above (minibuffer-window))
+                 (minibuffer-selected-window)
+                 (get-largest-window)))
           (when (and mode-line-format
                      (not (and (listp mode-line-format)
                                (assq 'eldoc-mode-line-string mode-line-format))))
-	    (setq mode-line-format
-		  (list "" '(eldoc-mode-line-string
-			     (" " eldoc-mode-line-string " "))
-			mode-line-format)))
+            (setq mode-line-format
+                  (list "" '(eldoc-mode-line-string
+                             (" " eldoc-mode-line-string " "))
+                        mode-line-format)))
           (setq eldoc-mode-line-string
                 (when (stringp format-string)
                   (apply #'format-message format-string args)))
@@ -327,8 +327,8 @@ Also store it in `eldoc-last-message' and return that value."
     ;; Emacs way of preventing log messages.
     (let ((message-log-max nil))
       (cond (eldoc-last-message
-	     (funcall eldoc-message-function "%s" eldoc-last-message))
-	    (omessage (funcall eldoc-message-function nil)))))
+             (funcall eldoc-message-function "%s" eldoc-last-message))
+            (omessage (funcall eldoc-message-function nil)))))
   eldoc-last-message)
 
 (defun eldoc--message-command-p (command)
@@ -350,8 +350,8 @@ Also store it in `eldoc-last-message' and return that value."
   (and eldoc-last-message
        (not (minibufferp))      ;We don't use the echo area when in minibuffer.
        (if (and (eldoc-display-message-no-interference-p)
-		(eldoc--message-command-p this-command))
-	   (eldoc--message eldoc-last-message)
+                (eldoc--message-command-p this-command))
+           (eldoc--message eldoc-last-message)
          ;; No need to call eldoc--message since the echo area will be cleared
          ;; for us, but do note that the last-message will be gone.
          (setq eldoc-last-message nil))))
@@ -667,9 +667,9 @@ Meant as a value for `eldoc-documentation-strategy'."
        (progn
          (defcustom ,secondary ,value ,docstring ,@more)
          (define-obsolete-variable-alias ',main ',secondary "eldoc-1.1.0"))
-       (progn
-         (defcustom ,main ,value ,docstring  ,@more)
-         (defvaralias ',secondary ',main ,docstring))))
+     (progn
+       (defcustom ,main ,value ,docstring  ,@more)
+       (defvaralias ',secondary ',main ,docstring))))
 
 (eldoc--documentation-strategy-defcustom eldoc-documentation-strategy
     eldoc-documentation-function
-- 
2.30.1

From 184d5aa6e4d594b044a62e15b6eab084da0abb29 Mon Sep 17 00:00:00 2001
From: Mathieu Marques <[email-masked]>
Date: Fri, 12 Mar 2021 19:45:18 +0100
Subject: [PATCH 2/2] * lisp/emacs-lisp/eldoc.el (eldoc--format-doc-buffer):
 Allow custom separator

---
 lisp/emacs-lisp/eldoc.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 485ea26379..93cb6e7df5 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -129,6 +129,13 @@ window.  If the value is the symbol `maybe', then the echo area
 is only skipped if the documentation doesn't fit there."
   :type 'boolean)
 
+(defcustom eldoc-documentation-separator ""
+  "Separator to use between each documentation thing, when multiple."
+  :type 'string)
+
+(defface eldoc-documentation-separator '((t (:extend t :inherit shadow)))
+  "Face to use for the separator between documentation things.")
+
 (defface eldoc-highlight-function-argument
   '((t (:inherit bold)))
   "Face used for the argument at point in a function's argument list.
@@ -490,7 +497,11 @@ This holds the results of the last documentation request."
                         ": "
                         this-doc))
                  do (insert this-doc)
-                 when rest do (insert "\n")
+                 when rest
+                 do (insert (concat
+                             "\n"
+                             (propertize eldoc-documentation-separator
+                                         'face 'eldoc-documentation-separator)))
                  finally (goto-char (point-min)))
         ;; Rename the buffer, taking into account whether it was
         ;; hidden or not
-- 
2.30.1