M-x
reapply-theme
at any point to update the theme based upon current Dark
Mode.
Importantly, this requires Emacs Plus
for the functionality to detect the current Dark Mode status. If you'd prefer
not to use Emacs Plus, you can make GUI work like the terminal version easily.
(use-package solarized-theme
:ensure t)
(setq my-light-theme 'solarized-light)
(setq my-dark-theme 'solarized-dark)
;;;; Do not change anything below here, just update the two variables above.
;; If not on a Mac, just load a theme
(when (not (eq system-type 'darwin))
(load-theme my-dark-theme t))
;; On a Mac
(when (eq system-type 'darwin)
;; Check if in terminal or GUI
(if window-system
;; GUI Emacs
(progn
(defun my/apply-theme (appearance)
"Load theme, taking current system APPEARANCE into consideration."
(mapc #'disable-theme custom-enabled-themes)
(pcase appearance
('light (load-theme my-light-theme t))
('dark (load-theme my-dark-theme t))))
(add-hook 'ns-system-appearance-change-functions #'my/apply-theme))
;; Terminal Emacs
(progn
(defun reapply-theme ()
"Check status of Dark Mode and apply appropriate pre-defined theme."
(interactive)
(let ((cmd-output (shell-command-to-string "defaults read -g AppleInterfaceStyle")))
(if (string-match-p "Dark" cmd-output)
(load-theme my-dark-theme t)
(load-theme my-light-theme t))))
(reapply-theme))))
Home |
Back to blog
This work is licensed under CC BY-NC 4.0