emacs: fix/generalise light/dark mode switching on darwin
Alan Pearce alan@alanpearce.eu
Sun, 09 Feb 2025 14:44:07 +0100
2 files changed, 21 insertions(+), 21 deletions(-)
M user/emacs/init.el → user/emacs/init.el
@@ -82,13 +82,7 @@ (doom-themes-org-config))) (use-package stimmung-themes :disabled t :config (progn - (require 'stimmung-themes-light-theme) - (let ((light-mode-theme 'stimmung-themes-light) - (dark-mode-theme 'stimmung-themes-dark) - (original-stimmung-themes-string stimmung-themes-string)) - (load-theme light-mode-theme :noconfirm :noenable) - (load-theme dark-mode-theme :noconfirm :noenable) - (enable-theme light-mode-theme) + (let ((original-stimmung-themes-string stimmung-themes-string)) (defun toggle-stimmung-string-highlighting () (interactive) (let ((current-theme (car custom-enabled-themes))) @@ -96,6 +90,23 @@ (setq stimmung-themes-string (if (eq stimmung-themes-string original-stimmung-themes-string) 'none original-stimmung-themes-string)) (load-theme current-theme :noconfirm))))))) + +(let ((light-mode-theme 'doom-one-light) + (dark-mode-theme 'doom-one)) + (load-theme light-mode-theme :noconfirm :noenable) + (load-theme dark-mode-theme :noconfirm :noenable) + (enable-theme light-mode-theme) + (defun my/switch-theme-variant (mode) + (interactive (list + (intern (completing-read "Make it: " '("light" "dark") nil t)))) + (cond + ((eq mode 'dark) + (disable-theme light-mode-theme) + (enable-theme dark-mode-theme)) + ((eq mode 'light) + (disable-theme dark-mode-theme) + (enable-theme light-mode-theme))) + (modify-all-frames-parameters '((ns-appearance mode))))) (global-set-key (kbd "<pinch>") 'ignore) (global-set-key (kbd "<C-wheel-up>") 'ignore)
M user/settings/darwin.nix → user/settings/darwin.nix
@@ -73,20 +73,9 @@ else MODE="light" fi emacsclient="${config.programs.emacs.finalPackage}/bin/emacsclient" - emacsSwitchTheme () { - if pgrep -q Emacs; then - if [[ $MODE == "dark" ]]; then - $emacsclient \ - --eval "(toggle-theme)" \ - --eval "(modify-all-frames-parameters '((ns-appearance '$MODE)))" - elif [[ $MODE == "light" ]]; then - $emacsclient \ - --eval "(toggle-theme)" \ - --eval "(modify-all-frames-parameters '((ns-appearance '$MODE)))" - fi - fi - } - emacsSwitchTheme + if pgrep -q Emacs; then + $emacsclient --eval "(my/switch-theme-variant '$MODE)" + fi '' ) )