Why Having Multiple Emacs Themes if Not Cycling Through Them
I don’t think I’m alone in having multiple Emacs themes installed. Am I?
After trying many, I have kept just a few:
- acme,
- gruvbox,
- material,
- nano,
- nova,
- plan9,
- solo-jazz,
- twilight-bright
There are a few great themes that I like from those coming with Emacs:
- adwaita
- dichromancy
- leuven
- modus-operandi
- tango
- tsdh-light
- whiteboard
At this point I reached my dilemma.
With so many themes available, how can I experience them all?
Enter my new Emacs daily theme cycle:
(defun alpo/today-emacs-theme ()
"Chooses a theme based on the day."
(interactive)
(let* ((themes-list (list 'acme 'gruvbox-light-hard 'dichromancy 'material-light 'leuven 'nano-light 'modus-operandi 'nova 'tsdh-light 'plan9 'solo-jazz 'twilight-bright))
(themes-len (length themes-list))
(today-as-number (string-to-number (format-time-string "%Y%m%d%j")))
(theme-index (% today-as-number themes-len))
(theme-sym (nth theme-index themes-list)))
(message "Loading theme: %s" theme-sym)
(load-theme theme-sym)))
(alpo/today-emacs-theme)
An unplanned benefit of the list of chosen themes is that it is not a multiple of 7 and thus the selected theme won’t be the same for the same day of the week.
Here’s what the function is doing:
- creates a list of themes to choose from
- construct a number based on the date (instead of going for a random I want the same theme for a day)
- calculate the theme index based using modulo operation