Different bg color between `emacsclient -nw` and `emacs -nw`

There are two ways to open Emacs in the terminal. emacsclient -nw (connects to an existing daemon) and emacs -nw (creates a new instance of Emacs in the terminal). The background of the daemon terminal frame will be different – sometimes an ugly shade of your chosen theme’s highlight.

(left: emacsclient -nw, right: emacs -nw)

This occurs because the solaire-mode plugin tries to use a slightly off-background color for your real, file-visiting buffers, but while this looks great in GUI Emacs…

It doesn’t in the terminal because terminals only support 256 colors (by default). There, a subtle shade is difficult to achieve, so Emacs approximates, and often does so poorly.

Doom disables solaire-mode when you start tty Emacs (emacs -nw), but cannot do this for daemon users; it cannot guess what kind of frame you’re will open, so it’s leave to users to disable it themselves.

Why is there no permanent solution?

Two reasons:

  1. Users can open graphical or terminal frames from a daemon session. It is impossible to guess which the user will use, primarily. Doom assumes GUI frames and leaves solaire-mode on (leaving it to uses to disable it otherwise).

  2. There is no such thing as frame-local themes or face customizations in Emacs, so solaire-mode cannot apply itself on a per-frame basis.

:pushpin: The :ui doom module does try to guess, but it appears to only work for some and not others, and will affect all open frames, graphical or otherwise.

What is the workaround?

There are two:

  1. Disable solaire-mode. If you intend to use Emacs primarily in the terminal.
    1. Add (package! solaire-mode :disable t) to ~/.doom.d/packages.el
    2. Run doom sync
    3. Restart Emacs.
  2. Adopt a terminal with 24-bit color support.

I want Emacs’ background to match my terminal

In addition to the workarounds above, the following snippet will make Emacs’ background “transparent”, therefore matching your terminal:

;; add to ~/.doom.d/config.el
(custom-set-faces!
  '(default :background nil))

:pushpin: Check out “How to switch, customize, or write themes” for more on customizing your theme’s faces.