Last active
April 3, 2024 18:37
-
-
Save ChrisRenfrow/8bb7eafd84235b2bdf56b5c1ebd2d767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; The following elisp automates switching my emacs theme between my preferred light and dark themes | |
;; based on my system color-scheme preference. | |
;; Specify light and dark (day and night) themes | |
(setq cr/day-theme 'modus-operandi | |
cr/night-theme 'modus-vivendi) | |
(defun cr/set-theme-by-gsettings-color-scheme () | |
"Sets the Doom Emacs theme based on the gsettings color-scheme preference" | |
(let ((prefer-dark (string= "'prefer-dark'" | |
(string-clean-whitespace (shell-command-to-string "gsettings get org.gnome.desktop.interface color-scheme"))))) | |
(if prefer-dark | |
;; Only load the theme if its opposite is set | |
(when (eq doom-theme cr/day-theme) | |
(load-theme cr/night-theme t)) | |
(when (eq doom-theme cr/night-theme) | |
(load-theme cr/day-theme t))))) | |
;; Cancel any timers running for this function | |
(cancel-function-timers 'cr/set-theme-by-gsettings-color-scheme) | |
;; Run function every 3 seconds to update the theme | |
(run-with-timer 0 3 'cr/set-theme-by-gsettings-color-scheme) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment