all repos — nixfiles @ 45425b88cff507d28640b0623f98949c049ae38a

System and user configuration, managed by nix and home-manager

emacs: fix/generalise light/dark mode switching on darwin
Alan Pearce alan@alanpearce.eu
Sun, 09 Feb 2025 14:44:07 +0100
commit

45425b88cff507d28640b0623f98949c049ae38a

parent

081a9da659babf65b57fe19f0d10ac5d031f6567

2 files changed, 21 insertions(+), 21 deletions(-)

jump to
M user/emacs/init.eluser/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.nixuser/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
                     ''
                   )
               )