guidoschmidt / circadian.el

Theme-switching for Emacs based on daytime
https://guidoschmidt.github.io/circadian.el
MIT License
175 stars 8 forks source link

Circadian crashes above arctic circle #27

Closed realcomplex closed 1 year ago

realcomplex commented 1 year ago

Hi! Thanks for the nice package, I'm happily using it.

I have an annoying edge case for you... I current live somewhere north of the arctic circle, and this means that there are currently no sunsets or sunrises. This means that (solar-sunrise-sunset (calendar-current-date)) evaluates to (nil nil "0:00") instead of the usual ((6.8833333337679505 "CET") (16.283333332277834 "CET") "9:24") (for example). This means that circadian--frac-to-time receives a value of nil when circadian is set up, and raises and error.

Could you possibly add a test for this somewhere? Ideally, of course, circadian should just use the "sunset" theme when the sun is currently down (which should be checked for somehow, since solar-sunrise-sunset will return nil regardless) and the "sunrise" theme when the sun is currently up.

Let me know if you would like me to have a stab at fixing this!

Backtrace:

Debugger entered--Lisp error: (wrong-type-argument numberp nil)
  floor(nil nil)
  cl-floor(nil)
  circadian--frac-to-time(nil)
  circadian-sunrise()
  circadian-match-sun(:sunrise)
  #f(compiled-function (entry) #<bytecode -0x85fcd1b0ef7a79>)((:sunrise . modus-operandi))
  mapcar(#f(compiled-function (entry) #<bytecode -0x85fcd1b0ef7a79>) ((:sunrise . modus-operandi) (:sunset . modus-vivendi)))
  circadian-themes-parse()
  circadian-activate-latest-theme()
  circadian-setup()
  (progn (setq circadian-themes '((:sunrise . modus-operandi) (:sunset . modus-vivendi))) (circadian-setup) t)
  ...
guidoschmidt commented 1 year ago

Nice find, I changed the two functions circadian-sunrise and circadian-sunset to check vor nil values and print errors in case:

⛔ Error (use-package): circadian/:init: No valid sunset from solar-sunrise-sunset, consider using fixed time strings, e.g. (setq circadian-themes ’(("9:00" . wombat) ("20:00" . tango)))
⛔ Error (use-package): circadian/:init: No valid sunrise from solar-sunrise-sunset, consider using fixed time strings, e.g. (setq circadian-themes ’(("9:00" . wombat) ("20:00" . tango)))

Hope this helps. Let me know if you'd consider any other behaviour as better or more convenient.