Homebrew-emacs-plus: Having trouble with dark mode in emacsclient

Created on 11 Aug 2020  路  12Comments  路  Source: d12frosted/homebrew-emacs-plus

I haven't used emacs for a while, but I noticed recently that setting ns-appearance does not change frames to dark mode in emacsclient. I tried with a minimal init file

(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))

In emacsclient, transparent title bar works but dark mode doesn't work. Both setting works in non-daemon emacs, however.

I'm currently running macOS 10.15.6 with emacs-plus 27.1. emacs-plus is installed using homebrew with option

--with-no-frame-refocus
daemon

All 12 comments

Hi @jaaasonSun ,

Could you please tell me how you start the server?

Hi @jaaasonSun ,

Could you please tell me how you start the server?

I usually start emacsclient and start emacs server (if necessary) with this script from this article

# Number of current visible frames,
# Emacs daemon always has a visible frame called F1
visible_frames() {
  emacsclient -a "" -e '(length (visible-frame-list))'
}

change_focus() {
  emacsclient -n -e "(select-frame-set-input-focus (selected-frame))" > /dev/null
}

# try switching to the frame incase it is just minimized
# will start a server if not running
test "$(visible_frames)" -eq "1" && change_focus

if [[ $* == *-nw* ]]
then
    emacsclient "$@" && change_focus
else
    emacsclient -n -c "$@" && change_focus
fi

But I've also tried starting emacs server with

emacs --daemon

and start emacsclient with

emacsclient -c -n

and dark mode doesn't work in both cases.

I could not reproduce when running it differently:

  1. Start Emacs.app.
  2. M-x server-mode.
  3. $ emacsclient testfile.txt.

But in some sense it's cheating. So maybe it's really related to the daemon mode. I think I've seen some similar reports related to daemon mode. 馃 Don't remember where and when.

Will play around with it later.

P. S. I don't understand how your script starts the emacs daemon. AFAIK, emacsclient doesn't work unless the server is running already. Apologies for dummy questions, I am not using emacsclient so might be missing something obvious here.

emacsclient -a EDITOR tries to start emacsclient with a fallback editor, and will start emacs daemon if no server is running and no fallback is provided.

  1. Start Emacs.app.
  2. M-x server-mode.
  3. $ emacsclient testfile.txt.

So I tried this but $ emacsclient testfile.txt defaults to opening the file in an existing frame (which afaik always exists because server-mode requires the Emacs.app running?), and since existing frame is started directly from Emacs.app, it is in dark mode (correctly).
With -c option emacsclient will start a new frame. In this case, I'm seeing the same behavior that the new frame is in light mode.

Thank you for explanations.

which afaik always exists because server-mode requires the Emacs.app running

yes, that's why I said that it's cheating :smile_cat:

With -c option emacsclient will start a new frame. In this case, I'm seeing the same behavior that the new frame is in light mode.

Can reproduce. Thanks :)

P. S. Can't provide any ETA :disappointed: but will keep it top in my priorities :)

Thank you so much for your help!

Update:

  • Bad news 1: setting ns-appearance to dark in emacs-plus@28 doesn't work in normal mode as well 馃槄
  • Bad news 2: another emacs formulae emacs-head exhibit the issue on the emacs@27 branch
  • Good news 馃帀: emacs-head@28 doesn't have issue with dark mode in both normal mode and emacsclient

These are the options used to build emacs-plus@28 and emacs-head@28

brew install emacs-plus@28 --with-xwidgets --with-no-frame-refocus --with-modern-cg433n-icon

brew install emacs-head@28 --with-cocoa --with-imagemagick --with-xwidgets

Sorry that I don't know much about homebrew formulae and how emacs is built so I couldn't be of much help. But emacs-plus and emacs-head seem quite similar. Hope this information will be of help.

@jaaasonSun thank you very much for the update. I am glad that you found a workaround with emacs-head.

@daviderestivo did you add anything special? Maybe some patch? 馃

@daviderestivo did you add anything special? Maybe some patch? 馃

@d12frosted to be honest I don't I have any special patch ...

@daviderestivo that's what I thought 馃樃 then it's strange that it works in emacs-head and doesn't work here 馃樃 馃し

I'm closing this issue because the behavior is completely due to my error, although I still cannot account for the difference between emacs-head and emacs-plus.

Two keys were written to defaults:

$ defaults read org.gnu.Emacs
{
    ... # omitted

    NSRequiresAquaSystemAppearance = true;
    TransparentTitleBar = DARK;
}

to (presumably) force emacs to use system dark mode before it was properly supported. Simply removing the lines with

$ defaults delete org.gnu.Emacs NSRequiresAquaSystemAppearance
$ defaults delete org.gnu.Emacs TransparentTitleBar

fixed everything in both emacs@28 and emacs@27 for me.

Wow, that was interesting. Thanks for reporting back 馃挴

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smallzhan picture smallzhan  路  7Comments

d12frosted picture d12frosted  路  6Comments

glepnir picture glepnir  路  6Comments

jonathanj picture jonathanj  路  3Comments

tshu-w picture tshu-w  路  6Comments