From 85cbf1be3ef5d4cb86cbe85f482d98cffc1934c4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Jan 2022 17:27:00 -0600 Subject: Reset +sunrise-sunset at midnight --- lisp/acdw.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lisp/acdw.el b/lisp/acdw.el index a4e12f1..47df30d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -37,7 +37,7 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." "If MKDIR is non-nil, the directory is created.\n" "Defined by `/define-dir'.") (let ((file-name (expand-file-name (convert-standard-filename file) - ,name))) + ,name))) (when mkdir (make-directory (file-name-directory file-name) :parents)) file-name)))) @@ -54,8 +54,11 @@ ARGS." (when msg (message "%s" msg))))) -(defun +sunrise-sunset (sunrise-command sunset-command) - "Run SUNRISE-COMMAND at sunrise, and SUNSET-COMMAND at sunset." +(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) ":" @@ -71,9 +74,12 @@ ARGS." (_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))) + (run-at-time sunrise-time nil sunrise-command) + (run-at-time sunset-time nil sunset-command) + (run-at-time "12:00am" nil sunset-command) + ;; Reset everything at midnight + (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. -- cgit 1.4.1-21-gabe81