This is an Emacs extension that allows user provided set of functions to run at some sun events - sunrise, midday (sun is at highest point for current coordinates), sunset and midnight (sun at lowest).
It’s inspired by some settings found in Juri Linkov’s .emacs.
The solar built-in package is used and the calendar-latitude and calendar-longitude variables must be set to appropriate location.
;; currently in Sofia, Bulgaria
(custom-set-variables
'(calendar-latitude 42.7)
'(calendar-longitude 23.3))
(require 'rase)
;; load without enabling some GNU/Emacs 24 built-in themes
(load-theme 'whiteboard t t)
(load-theme 'wombat t t)
;; create a two-argument function to be invoked at sun events
(defun switch-themes (sun-event &optional first-run)
"Switch themes on sunrise and sunset."
(if first-run ; set theme on initialization
(cond ((memq sun-event '(sunrise midday))
(disable-theme 'wombat)
(enable-theme 'whiteboard))
((memq sun-event '(sunset midnight))
(disable-theme 'whiteboard)
(enable-theme 'wombat)))
(cond ((eq sun-event 'sunrise) ; after initialization deal only
(disable-theme 'wombat) ; with sunrise and sunset
(enable-theme 'whiteboard))
((eq sun-event 'sunset)
(disable-theme 'whiteboard)
(enable-theme 'wombat)))))
;; sign this function to be invoked on sun events
(add-hook 'rase-functions 'switch-themes)
;; start the run-at-sun-event daemon, invoking hooks immediately
(rase-start t)
;; you can stop it like this
;;(rase-stop)