Support for dark/light theme switching (match OS preference, e.g. under macOS)
- Dominant language
- Emacs Lisp
- Stars
- 22.7k
- Forks
- 3.1k
- Avg merge
- 10h 46m
- Merged PRs (30d)
- 4
Description
### Describe your request
macOS allows the user to specify a preference for a dark or light UI theme, with apps adapting both UI elements and (in some cases) their content presentation to match the user preference. E.g. browsers forward the preference to websites via the `prefers-color-scheme` CSS media query; editors switch syntax highlighting themes; etc.
The feature could be implemented by asking the user to define their preferred light and dark mode themes, with sensible defaults, e.g. instead of (or in addition to) `(setq doom-theme ...)`, the user could specify `(setq doom-theme-dark 'modus-vivendi doom-theme-light 'modus-operandi)`.
In my current personal config (I'm in the process of giving Doom Emacs a try), I have the following snippet:
```emacs-lisp
(setq system-is-mac (equal 'darwin system-type))
(defun get-appearance-preferences ()
(if system-is-mac
(do-applescript "
tell application \"System Events\"
tell appearance preferences
if (dark mode) then
return dark
else
return light
end if
end tell
end tell
")
"dark")
```
This is accompanied by https://github.com/cormacrelf/dark-notify and a shell script that is running in the background (installed manually in system preferences / users / login items):
```shell
#!/bin/sh
set -eu
# brew install cormacrelf/tap/dark-notify
export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH
exec dark-notify -c "emacsclient -e '(update-theme)'"
```
The function `update-theme` polls `get-appearance-preferences` and selects the preferred theme.
Of course it would be wonderful if this scheme was OS-independent (I'm also an OpenBSD user, but I'm not sure what's the standard method for specifying dark/light preference), and if it required less manual setup on macOS (although that's probably something that Emacs itself should address).
### Briefly explain its use-case
The user can specify the variables `doom-theme-dark` and `doom-theme-light` (with sane defaults), and Emacs automatically chooses the theme based on these preferences, and the current system setting. Ideally, Emacs switches between light/dark mode whenever the rest of the system does.
Contributor guide
Assessment
This issue has not been assessed yet.