all repos — nixfiles @ aedea00a8b6ccbbeea0ea0215af0652ff7ccbd28

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

user/settings/emacs/theme.el (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;; -*- lexical-binding: t; -*-
(use-package @package@
  :if (or (daemonp)
          window-system))

(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)
             (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))

  (use-package kqueue
    :if (and (eq system-type 'darwin)
             window-system )
    :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)))))