Subject: Re: bug#56459: 29.0.50; Edebug disables Eldoc

From: Dmitry Gutov <[email-masked]>
Date: Wed, 1 Mar 2023 21:19:05 +0200

On 01/03/2023 18:57, Eli Zaretskii wrote:
>> Date: Wed, 1 Mar 2023 18:06:56 +0200
>> Cc:[email-masked],[email-masked],[email-masked],
>>   [email-masked]
>> From: Dmitry Gutov<[email-masked]>
>>
>> On 01/03/2023 17:49, Eli Zaretskii wrote:
>>>> Cc:[email-masked],[email-masked],[email-masked],
>>>>    [email-masked]
>>>> Date: Wed, 01 Mar 2023 17:42:07 +0200
>>>> From: Eli Zaretskii<[email-masked]>
>>>>
>>>> So I've now reverted that change, and I'm reopening the bug.  It will
>>>> have to be fixed in some other way.
>>> One possibility would be to show the ElDoc info on the mode line when
>>> Edebug is active.  But the difficulty with that is to figure out how
>>> to revert the mode line to the original shape when Edebug finishes.
>>> We currently show the info on the mdoe line when the current buffer is
>>> a minibuffer, and remove the info in minibuffer-exit-hook, but how to
>>> do that in the Edebug case?
>> edebug-mode-hook?
> That's a starting point, but I don't think it's enough, because you
> could switch to another buffer without exiting Edebug.  I tried
> something like that and it didn't work well enough.  But maybe my
> testing was incorrect, so if you are confident that this fixes the
> problem, feel free to install (perhaps on master, though).

We could try to use more hooks, or give up and use post-command-hook.

Also switched to looking up edebug-mode instead of edebug-active because 
the latter is a global value.

diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 3f5cf0ad0dc..493ec18446f 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -296,13 +296,10 @@ eldoc-minibuffer-message
  This function displays the message produced by formatting ARGS
  with FORMAT-STRING on the mode line when the current buffer is a 
minibuffer.
  Otherwise, it displays the message like `message' would."
-  (if (minibufferp)
+  (defvar edebug-mode)
+  (if (or edebug-mode (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)
+        (add-hook 'post-command-hook #'eldoc-minibuffer--cleanup)
  	(with-current-buffer
  	    (window-buffer
  	     (or (window-in-direction 'above (minibuffer-window))
@@ -321,6 +318,14 @@ eldoc-minibuffer-message
            (force-mode-line-update)))
      (apply #'message format-string args)))

+(defun eldoc-minibuffer--cleanup ()
+  (defvar edebug-mode)
+  (unless (or edebug-mode (minibufferp))
+    (setq eldoc-mode-line-string nil
+          ;; https://debbugs.gnu.org/16920
+          eldoc-last-message nil)
+    (remove-hook 'post-command-hook #'eldoc-minibuffer--cleanup)))
+
  (make-obsolete
   'eldoc-message "use `eldoc-documentation-functions' instead." 
"eldoc-1.1.0")
  (defun eldoc-message (&optional string) (eldoc--message string))