From eca7b640967eab0806d0b5eb72983ae95b715c7a Mon Sep 17 00:00:00 2001 From: Grégoire Duchêne Date: Sat, 11 Jan 2025 15:49:44 +0000 Subject: darwin/emacs: Automatically pick and switch themes --- dotfiles-darwin/emacs/functions.el | 9 +++++++++ dotfiles-darwin/emacs/init.el | 7 +------ emacs/init.el | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/dotfiles-darwin/emacs/functions.el b/dotfiles-darwin/emacs/functions.el index c9b16be..1c57e59 100644 --- a/dotfiles-darwin/emacs/functions.el +++ b/dotfiles-darwin/emacs/functions.el @@ -33,3 +33,12 @@ map) t nil "Use %k to resize the frame"))) + +(defun my/set-frame-themes () + "Configure themes, including theme switching." + (let ((day-theme (seq-random-elt (alist-get 'day my/themes))) + (night-theme (seq-random-elt (alist-get 'night my/themes)))) + (load-theme day-theme :no-confirm :no-enable) + (load-theme night-theme :no-confirm :no-enable) + (run-at-time nil (* 15 60) #'my/maybe-switch-theme day-theme night-theme + #'my/macos-dark-p))) diff --git a/dotfiles-darwin/emacs/init.el b/dotfiles-darwin/emacs/init.el index b0ef91a..57812e4 100644 --- a/dotfiles-darwin/emacs/init.el +++ b/dotfiles-darwin/emacs/init.el @@ -27,12 +27,7 @@ ;; Theme Management -(when (or window-system (daemonp)) - (my/with-add-hook 'after-init-hook - (when my/day-theme (load-theme my/day-theme :no-confirm :no-enable)) - (when my/night-theme (load-theme my/night-theme :no-confirm :no-enable)) - (run-at-time nil (* 15 60) #'my/maybe-switch-theme my/day-theme - my/night-theme #'my/macos-dark-p))) +(add-hook 'after-init-hook #'my/set-frame-themes) ;; “Window” Management diff --git a/emacs/init.el b/emacs/init.el index fe0cbff..7604227 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -108,17 +108,25 @@ ;; Theme Management -(defvar my/day-theme nil "Theme to use during the day.") - -(defvar my/night-theme nil "Theme to use during the night.") - -(defvar my/fonts +(defconst my/fonts '((:family "Iosevka Fixed Slab" :height 140) (:family "Iosevka SS04" :height 140) (:family "Iosevka" :height 140) (:family "Menlo" :height 120)) "Fonts to try as default.") +(defconst my/themes + `((day . (adwaita + leuven + modus-operandi + tango + ,nil)) + (night . (tango-dark + misterioso + modus-vivendi + wombat))) + "Themes to try.") + (let ((hook (cond ((daemonp) 'server-after-make-frame-hook) (window-system 'after-init-hook)))) (when hook (add-hook hook #'my/set-frame-font))) -- cgit v1.2.3-70-g09d2