From 1a1e26f23da81c7d78d4c81235af85a67d68752e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 25 Dec 2021 12:23:45 -0600 Subject: Change circadian to +sunrise-sunset I think this'll be less buggy overall. --- lisp/acdw.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index b13c9b6..0f78c79 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -42,5 +42,39 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." (make-directory (file-name-directory file-name) :parents)) file-name)))) + +(defun +suppress-messages (oldfn &rest args) ; from pkal + "Advice wrapper for suppressing `message'. +OLDFN is the wrapped function, that is passed the arguments +ARGS." + (let ((msg (current-message))) + (prog1 + (let ((inhibit-message t)) + (apply oldfn args)) + (when msg + (message "%s" msg))))) + + +(defun +sunrise-sunset (sunrise-command sunset-command) + "Run SUNRISE-COMMAND at sunrise, and SUNSET-COMMAND at sunset." + (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-time (match-string 1 ss)) + (sunset-time (match-string 2 ss))) + (run-at-time sunrise-time (* 60 60 24) sunrise-command) + (run-at-time sunset-time (* 60 60 24) sunset-command) + (run-at-time "12:00am" (* 60 60 24) sunset-command)))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81