Automatically adjusting Emacs to macOS switches in appearance
04 Jun 2023 Charles Choi
Count me among those who likes using the Auto setting when adjusting the appearance in macOS to either light or dark. Native macOS apps that are coded accordingly can automatically adjust as well, and it turns out that the Yamamoto Mitsuharu fork of Emacs (aka emacs-mac-app) can do this too. But with emacs-mac-app, just because it can detect the appearance change doesn’t mean that all the themes or faces will adjust accordingly too. As such it is typically up to the user to write a pair of custom light and dark mode functions to invoke when the appearance change happens.
For quite some time I’ve been calling these appearance mode functions manually like an animal. Then I recently learned that mac-effective-appearance-change-hook
is a thing.
This hook gets invoked upon a macOS appearance change, so it becomes straightforward to write a hook function that tests for the :appearance
property returned by
(mac-application-state)
.
1 2 3 4 5 6 7 |
|
A caveat though: the above code will only work with the Yamamoto fork of Emacs for macOS. As of now there seems to be no consensus on how to handle OS-level appearance changes by Emacs core. That said, if the above works for you, then no more manual appearance change calls!
References
- Elisp code for cc/reconfigure-nsappearance
- Where to get emacs-mac-app: