From adf815b61bfd850e948e60b743ce48b0ff42d901 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 21 Jan 2022 16:34:55 -0600 Subject: Two out of three ain't bad --- lisp/acdw.el | 52 +--------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index 34d1bc4..4e5afb5 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -20,6 +20,7 @@ ;;; Code: (require 'diary-lib) +(require 'solar) ; for +sunrise-sunset ;;; Define a directory and an expanding function @@ -55,57 +56,6 @@ ARGS." (when msg (message "%s" msg))))) -(defun +sunrise-sunset--encode (time) - "Encode diary-style time string into a time. -This is stolen from `run-at-time'." - (let ((hhmm (diary-entry-time time)) - (now (decode-time))) - (encode-time (list 0 (% hhmm 100) (/ hhmm 100) - (decoded-time-day now) - (decoded-time-month now) - (decoded-time-year now) - nil -1 - (decoded-time-zone now))))) - -(defun +sunrise-sunset (sunrise-command sunset-command &optional reset) - "Run SUNRISE-COMMAND at sunrise, and SUNSET-COMMAND at sunset. -With RESET, this function will call itself with its own -arguments. That's really only useful within this function -itself." - (let* ((times-regex (rx (* nonl) - (: (any ?s ?S) "unrise") " " - (group (repeat 1 2 digit) ":" - (repeat 1 2 digit) - (: (any ?a ?A ?p ?P) (any ?m ?M))) - (* nonl) - (: (any ?s ?S) "unset") " " - (group (repeat 1 2 digit) ":" - (repeat 1 2 digit) - (: (any ?a ?A ?p ?P) (any ?m ?M))) - (* nonl))) - (ss (+suppress-messages #'sunrise-sunset)) - (_m (string-match times-regex ss)) - (sunrise (match-string 1 ss)) - (sunset (match-string 2 ss)) - (sunrise-time (+sunrise-sunset--encode sunrise)) - (sunset-time (+sunrise-sunset--encode sunset))) - (cond - ((time-less-p nil sunrise-time) - ;; If it isn't sunrise yet, it's still dark---and so we need to run the - ;; sunset-command. - (funcall sunset-command) - (run-at-time sunrise nil sunrise-command)) - ((time-less-p nil sunset-time) - ;; If it isn't sunset yet, it's still light---so we need to run the - ;; sunrise-command. - (funcall sunrise-command) - (run-at-time sunset nil sunset-command)) - (t (run-at-time "12:00am" nil sunset-command))) - ;; Reset everything at midnight - (unless reset - (run-at-time "12:00am" (* 60 60 24) - #'+sunrise-sunset sunrise-command sunset-command t)))) - (defun +ensure-after-init (function) "Ensure FUNCTION runs after init, or now if already initialized. If Emacs is already started, run FUNCTION. Otherwise, add it to -- cgit 1.4.1-21-gabe81