aboutsummaryrefslogtreecommitdiff
path: root/bard-elisp/bard-theme.el
blob: e00736df0fe5a8ddf8852a49be15a99f20b01cfc (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(setq fontaine-presets
        '((default
           :default-height 140
           :default-family "Iosevka Comfy"
           :variable-pitch-family "Iosevka Comfy Motion"
           :variable-pitch-height 1.0
           :fixed-pitch-family "Iosevka Comfy"
           :fixed-pitch-height 1.0
           :bold-weight bold
           :mode-line-active-family "Iosevka Comfy Motion"
           :mode-line-inactive-family "Iosevka Comfy Motion"
           :mode-line-active-height 140
           :mode-line-inactive-height 140
           )
          (tiny
           :inherit default
           :default-height 135)
          (wide
           :inherit default
           :default-family "Iosevka Comfy Wide"
           :fixed-pitch-family "Iosevka Comfy Wide"
           :mode-line-active-family "Iosevka Comfy Wide Motion Duo"
           :mode-line-inactive-family "Iosevka Comfy Wide Motion Duo"
           :variable-pitch-family "Iosevka Comfy Wide Motion Duo")
          (large
           :inherit default
           :variable-pitch-family "Iosevka Comfy Wide Motion"
           :default-height 170
           :mode-line-active-height 150
           :mode-line-inactive-height 150
           )
          (huge
           :inherit default
           :variable-pitch-family "Iosevka Comfy Wide Motion"
           :default-height 200
           :mode-line-active-height 170
           :mode-line-inactive-height 170
           )
          (t
           :default-family "Monospace"
           )))

;;; Switching themes
(defun bard/disable-all-themes ()
  "disable all active themes."
  (interactive)
  (dolist (i custom-enabled-themes)
    (disable-theme i)))

(defvar bard/after-theme-load-hook nil
  "Hook that runs after a new theme is loaded using `bard/select-theme`.")

(dolist (hook '(bard/after-theme-load-hook))
  (add-hook hook #'fontaine-apply-current-preset)
  (add-hook hook #'logos-update-fringe-in-buffers)
  (add-hook hook #'bard/update-ryo-cursor-color))

(defun bard/select-theme (&optional theme)
  "Enable the specified THEME, or prompt the user to select one if THEME is nil."
  (interactive
   (list
    (completing-read "Select theme: "
                     (mapcar 'symbol-name (custom-available-themes)))))
  (let* ((theme-symbol (if (symbolp theme) theme (intern theme)))
         (theme-name (symbol-name theme-symbol))
         (display-theme-name (if (string-suffix-p "-theme" theme-name)
                                 (substring theme-name 0 -6)
                               theme-name))
         (colored-theme-name (propertize display-theme-name 'face '(:weight bold))))
    (bard/disable-all-themes)
    (load-theme theme-symbol t)
    (message "Loaded the %s theme" colored-theme-name)
    (run-hooks 'bard/after-theme-load-hook)))

(defun bard/update-ryo-cursor-color ()
  "Update the color variable of `ryo-modal-mode' cursor to match the ef/modus theme."
  (let ((active-theme (car custom-enabled-themes))
        (cursor-color nil))
    (cond
     ((and (fboundp 'ef-themes-with-colors)
           (string-prefix-p "ef-" (symbol-name active-theme)))
      (ef-themes-with-colors
        (setq ryo-modal-cursor-color cursor
              ryo-modal-default-cursor-color cursor)))
     ((and (fboundp 'modus-themes-with-colors)
           (string-prefix-p "modus-" (symbol-name active-theme)))
      (modus-themes-with-colors
        (setq ryo-modal-cursor-color cursor
              ryo-modal-default-cursor-color cursor)))
     (t (setq cursor-color "red"))
     (setq ryo-modal-cursor-color cursor-color
           ryo-modal-default-cursor-color cursor-color))))

(provide 'bard-theme)