51 lines
2 KiB
Org Mode
51 lines
2 KiB
Org Mode
#+TITLE: Auto change emacs theme
|
|
#+AUTHOR: Yann Esposito
|
|
#+EMAIL: yann@esposito.host
|
|
#+DATE: [2019-09-30 Mon]
|
|
#+KEYWORDS: emacs
|
|
#+DESCRIPTION: A small snippet to automatically change theme in emacs.
|
|
#+OPTIONS: auto-id:t
|
|
|
|
One thing I kind of like is the ability to change emacs theme depending of
|
|
the hour.
|
|
There are two possibilities.
|
|
One would be to sync with the sun using the current location.
|
|
There is an emacs package for that.
|
|
It's called [[https://github.com/hadronzoo/theme-changer][theme-changer]] which at the timme of writing those lines is
|
|
asking for a new maintainer.
|
|
This theme changer is very elegant because like macOS use the location to
|
|
determine if it is day or night.
|
|
But I wanted to have more themes from morning to night:
|
|
|
|
1. early morning: deep yellow (gruvbox-light),
|
|
2. morning: light yellow (solarized-light),
|
|
3. day: grey/blueish during the day (nord-light),
|
|
4. evening: deep yellow again (gruvbox-light)
|
|
5. night: dark theme (oceanic-next)
|
|
6. sleep time: neon-like (laserwave)
|
|
|
|
And also, I wanted that to follow my working hours and not really the sun.
|
|
I might change my mind and use the code of theme-changer to follow the
|
|
curve of the sun.
|
|
But for now, just using straight hours should be good enough.
|
|
|
|
#+BEGIN_SRC elisp
|
|
(defun y/update-theme ()
|
|
"depending on time use different theme"
|
|
;; very early => gruvbox-light, solarized-light, nord-light
|
|
(let* ((hour (nth 2 (decode-time (current-time))))
|
|
(theme (cond ((<= 7 hour 8) 'doom-gruvbox-light)
|
|
((= 9 hour) 'doom-solarized-light)
|
|
((<= 10 hour 16) 'doom-nord-light)
|
|
((<= 17 hour 18) 'doom-gruvbox-light)
|
|
((<= 19 hour 22) 'doom-oceanic-next)
|
|
(t 'doom-laserwave))))
|
|
(when (not (equal doom-theme theme))
|
|
(setq doom-theme theme)
|
|
(load-theme doom-theme))))
|
|
|
|
(y/update-theme)
|
|
;; try to update the theme every minute
|
|
(run-with-idle-timer 0 60 'y/update-theme)
|
|
#+END_SRC
|