Circadian Emacs

The other day I was thinking about ways to automatically change from a light theme to a dark theme at a specific time of day in Emacs. Currently I have a custom function mapped to C-x t which tracks between the Solarized Light and Solzarized Dark themes.

A quick look at the GNU Emacs elisp manual led me to run-at-time which can trigger a function at specified times. This was a start and I quickly came up with (run-at-time "19:00" 43200 mp/theme-toggle). So every 12 hours, we flip back to whichever is not the current theme. Since I only have light and dark, this is pretty basic.

But this got me thinking, could I sync to sunrise and sunset? Or connect with Redshift? A quick search led me to the Circadian project on GitHub. Cool! So.. since I’m already using use-package, setup is a breeze. Put this in your init.el and run M-x eval-buffer.

(use-package solarized-theme
  :ensure
  :defer
  :init
    (progn
      (setq solarized-use-more-italic t
            solarized-distinct-fring-background nil
            solarized-high-contrast-mode-line nil))
  :config
    (progn
      (setf frame-background-mode 'light)
      (global-hl-line-mode 1)))

(use-package circadian
  :ensure t
  :config
  (setq calendar-latitude 59.3)
  (setq calendar-longitude 18.0)
  (setq circadian-themes '((:sunrise . solarized-light)
                           (:sunset . solarized-dark)))
  (circadian-setup))

You’ll now see ‘circadian.el – enabled solarized-light’ displayed in the minibuffer!

Leave a Reply

Your email address will not be published. Required fields are marked *