theme: extract emacs-specific theme setup
1 file changed, 62 insertions(+), 0 deletions(-)
changed files
A user/settings/emacs/theme.el
@@ -0,0 +1,62 @@ +;; -*- lexical-binding: t; -*- +(setq is-macport (featurep 'term/mac-win)) + +(use-package @package@ + :if (or (daemonp) + window-system) + :config (progn @config@)) + +(let ((light-mode-theme '@light-mode-theme@) + (dark-mode-theme '@dark-mode-theme@)) + (mapc #'disable-theme custom-enabled-themes) + (load-theme light-mode-theme :noconfirm :noenable) + (load-theme dark-mode-theme :noconfirm :noenable) + + (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))) + ) + + (defun my/system-appearance () + (if (and (eq system-type 'darwin) + (if is-macport + (string-equal + "NSAppearanceNameDarkAqua" + (plist-get (mac-application-state) :appearance)) + (string-equal + "Dark" + (string-trim-right (shell-command-to-string "defaults read -g AppleInterfaceStyle"))))) + 'dark + 'light)) + + (defun my/match-theme-system-appearance () + (interactive) + (my/switch-theme-variant (my/system-appearance))) + + (my/switch-theme-variant (my/system-appearance)) + + (add-hook 'mac-effective-appearance-change-hook + #'my/match-theme-system-appearance) + + (use-package kqueue + :if (and (eq system-type 'darwin) + window-system + (not (fboundp 'mac-application-state))) + :config (progn + (defun my/gp-notify-callback (event) + (let* ((filename (elt event 2)) + (basename (file-name-nondirectory filename))) + (when (string-equal basename ".GlobalPreferences.plist") + (my/match-theme-system-appearance)))) + (setq my/kq-watcher-global-preferences + (kqueue-add-watch (expand-file-name "~/Library/Preferences/") + '(write) + #'my/gp-notify-callback)))))