Subject: bug#79404: [BUG] eldoc-last-message should be a buffer-local variable

From: Lua Viana Reis <[email-masked]>
Date: Sun, 7 Sep 2025 21:51:33 +0000 (UTC)

Hi all,

Today I was wondering why the Eldoc echo area message kept flickering 
when I moved around the file. After inpecting eldoc.el, I found from the 
comment above the function "eldoc-pre-command-refresh-echo-area" that 
this should not be the case and something was broken:

> ;; This function goes on pre-command-hook.
> ;; Motion commands clear the echo area for some reason,
> ;; which make eldoc messages flicker or disappear just before motion
> ;; begins.  This function reprints the last eldoc message immediately
> ;; before the next command executes, which does away with the flicker.
> ;; This doesn't seem to be required for Emacs 19.28 and earlier.
> ;; FIXME: The above comment suggests we don't really understand why
> ;; this is needed.  Maybe it's not needed any more, but if it is
> ;; we should figure out why.
> (defun eldoc-pre-command-refresh-echo-area ()
>   "Reprint `eldoc-last-message' in the echo area."
>   (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)
>          ;; 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))))

So I used debug-on-variable-change to find out what was going on, and 
found that the variable eldoc-last-message was being set to nil 
immediately after being set. This variable is not buffer-local, and the 
"(special-mode)" call in eldoc-doc-buffer-separator (called on every 
eldoc message) would trigger "(global-eldoc-mode-enable-in-buffer)" 
which in turn resets the global value to nil.

This is the bug, and I think the simple solution is to make it 
buffer-local, which fixes the issue:

(make-variable-buffer-local 'eldoc-last-message)

I don't see why this variable should be global, but if there is a good 
reason, then perhaps eldoc-last-message should not be set to nil in the 
(eldoc-mode) function, or something else should be done to prevent this 
feedback loop from happening.

Perhaps this bug report can also serve as an explanation for the person 
who wrote "FIXME", because eldoc-pre-command-refresh-echo-area is still 
necessary to prevent the flicker (given that the main issue is solved).

kind regards,

Lua