💾 Archived View for her.esy.fun › posts › 0014-change-emacs-theme-automatically › index.gmi captured on 2023-09-08 at 15:49:47. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

Auto change emacs theme

author: Yann Esposito

email: yann@esposito.host

gpg

date: [2020-09-22 Tue]

keywords: emacs

description: A small snippet to automatically change theme in emacs.

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

theme-changer

which at the time 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.

So here is my piece of code I added to my doom-emacs =config.el=:

(defun y/auto-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 t))
    ;; run that function again next hour
    (run-at-time (format "%02d:%02d" (+ hour 1) 0) nil 'y/auto-update-theme)))

(y/auto-update-theme)

I'm still playing with it.

So there still might be a bug.

Use at your own risk.

Happy hacking to all of you.

Home

Feed

Slides

About

code

bookmarks

notes