Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background color in emacsclient is incorrect #50

Open
thomasheartman opened this issue Nov 9, 2018 · 4 comments
Open

Background color in emacsclient is incorrect #50

thomasheartman opened this issue Nov 9, 2018 · 4 comments

Comments

@thomasheartman
Copy link

thomasheartman commented Nov 9, 2018

Context: I'm running Ubuntu in WSL on Windows 10. Using Emacs through the terminal (Fish, if it changes anything).

The problem:
When running emacsclient, the background is incorrectly colored blue rather than the correct background color, which in this case would be to use the terminal's background color. The issue only occurs when running that one command (it works fine if I start it with emacs), and it does not seem to affect any other themes. I'm not really sure what is to blame here or whether it's on your end or mine, but considering it seems to only affect this theme, I thought I would raise this issue to at least see if you could offer any insights.

Please see the attached images for details. I'd be happy to provide you with more info if you let me know what you need.
One dark run with the emacs command
one_dark

One dark run with the emacsclient command. Background is solid blue.
one_dark_emacsclient

Tomorrow night theme run with the emacsclient command. Background is transparent (same color as the terminal).
tomorrow_night_emacsclient

EDIT:
This bit of code in my config file might be relevant, though I did try disabling it and restarting the server to no effect. It is run as a 'window-setup-hook.

(defun on-after-init()
  (unless (display-graphic-p (selected-frame))
  (set-face-background 'default "unspecified-bg" (selected-frame)))))
@jclosure
Copy link

jclosure commented Mar 2, 2021

I have the same issue. I'm not doing anything special.

(use-package atom-one-dark-theme
  :demand t
  :config
  (progn
    (load-theme 'atom-one-dark)))

Example in emacsclient:
image

I have read that when you run emacs server, frame is not available until you attach an emacsclient. I've seen ppl recommending solutions like:

(add-hook 'after-make-frame-functions
          (lambda (_f) (load-theme 'atom-one-dark t)))

However, the issue still persists and appears to not be related to frame.

In the terminal, I am running the client+server like this:

$ export TERM=xterm-256color
$ emacsclient --nw --alternate-editor=''

This automatically starts the emacs server and attaches to it, but for some reason atom-one-dark's background is the same blue.

Finally, I don't see this issue with other themes. Example:

(load-theme 'tango-dark)

Has the correct background in emacsclient. So I'm pretty sure this issue is with atom-one-dark-theme.

@jclosure
Copy link

jclosure commented Mar 2, 2021

I found a workaround. Not pretty, but it does address the issue.

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (defun my/theme-init-daemon (frame)
                (with-selected-frame frame
                  (load-theme 'atom-one-dark))
                ;; Run this hook only once.
                (remove-hook 'after-make-frame-functions
                             #'my/theme-init-daemon)
                (fmakunbound 'my/theme-init-daemon)))
  (load-theme 'atom-one-dark))

It seems the issue is with frame availability at the time the theme is loaded. I wonder if, similar logic could be added to the theme to handle emacsclient use cases.

@thomasheartman
Copy link
Author

thomasheartman commented Mar 3, 2021

@jclosure Huh; neat! I don't currently use this theme anymore, but that's good to know. Do you happen to know why it only seems to impact this theme? Or is that because it's the first theme loaded?

@jclosure
Copy link

It's because of this line:

(let* ((256color (eq (display-color-cells (selected-frame)) 256))

When it runs, it's expecting either 24bit or 256 color. The var 256color was false, even through I had:

export TERM=xterm-256color

What I needed to do was to instruct my terminal how to support 24bit, then everything looked perfect.

#!/bin/bash

# adds a terminfo entry defining a new terminal xterm-24bit
# If you run emacs (26.1+) setting TERM=xterm-24bit, then it
# will use 24bit color


cd $(mktemp -d)
cat <<EOF > terminfo-24bit.src
# Use colon separators.
xterm-24bit|xterm with 24-bit direct color mode,
  use=xterm-256color,
  setb24=\E[48:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm,
  setf24=\E[38:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm,
# Use semicolon separators.
xterm-24bits|xterm with 24-bit direct color mode,
  use=xterm-256color,
  setb24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
  setf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
EOF

tic -x -o ~/.terminfo terminfo-24bit.src
rm terminfo-24bit.src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants