Subject: bug#78896: 29.4; display-time-mode breaks minibuffer in emacsclient

From: Eli Zaretskii <[email-masked]>
Date: Thu, 26 Jun 2025 08:11:19 +0300

> Cc: [email-masked]
> From: Juri Linkov <[email-masked]>
> Date: Wed, 25 Jun 2025 21:57:30 +0300
> 
> > Given the following minimal init file:
> > ```
> > ;; min-init.el
> > (require 'tab-bar)
> > (tab-bar-mode)
> > (add-to-list 'tab-bar-format 'tab-bar-format-global 'append)
> > (display-time-mode -1)
> > ```
> >
> > I do the following:
> > ```
> > emacs -Q --daemon --load min-init.el
> > ```
> >
> > Then when I start emacsclient in the terminal with `emacsclient -t`, the
> > minibuffer won't work at all. When I don't do this via the server,
> > e.g. removing `--daemon` from the above invocation, the minibuffer works
> > fine.
> >
> > Let me try to describe what I mean when I say that the minibuffer
> > doesn't work. `M-x` puts the cursor at the beginning of the minibuffer
> > (no "M-x" text). Typing any key says that the key is not defined. `C-g`
> > doesn't work either.
> 
> Thanks for the bug report.  My guess is that it's related
> to forcing switching frame focus to the active minibuffer.
> 'tab-bar-format-global' calls 'format-mode-line' that
> on a tty frame forces focus to the initial daemon frame.

These kinds of initializations and customizations should be moved to
server-after-make-frame-hook.  They should only be invoked directly
from the init file in non-daemon session (one could use the function
daemonp to check that).  The rule is that any initialization or
customization that needs the Emacs GUI system to be up and running
should be done from server-after-make-frame-hook.

Note that server-after-make-frame-hook is run after starting each new
frame, not just once.  So if you have one-time initializations, you
need some state variable you can set to indicate that the one-time
stuff was already done, and set it after performing those
initializations for the first time.