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.
---
 init.el      | 15 +++------------
 lisp/acdw.el | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/init.el b/init.el
index 86dca9a..45133df 100644
--- a/init.el
+++ b/init.el
@@ -257,10 +257,6 @@
   (:face aw-mode-line-face ((t (:foreground "red"))))
   (+ace-window-display-mode +1))
 
-(setup (:straight acme-theme)
-  ;; (load-theme 'acme t)
-  )
-
 (setup (:straight anzu)
   (:option anzu-cons-mode-line-p nil)
   (:+key [remap query-replace] 'anzu-query-replace-regexp
@@ -295,16 +291,10 @@
   (:hook-into eshell-mode
               comint-mode))
 
-(setup (:straight circadian)
-  (:option circadian-themes '((:sunrise . modus-operandi)
-                              (:sunset . modus-vivendi)))
-  (add-hook 'after-init-hook 'circadian-setup))
-
 (setup (:straight circe)
   (:require _circe
             +circe)
   (:also-load circe-chanop)
-  ;;(autoload '+irc "+circe" "Connect to IRC." t)
 
   ;; Formatting options
   (:option circe-format-action (format (format "%%%ds* {nick} {body}"
@@ -386,7 +376,7 @@
     (:option (append topsy-mode-functions)
              '(circe-channel-mode . +circe-current-topic)))
 
-  (add-hook 'circadian-after-load-theme-hook 'circe-nick-color-reset)
+  (add-hook 'modus-themes-after-load-theme-hook 'circe-nick-color-reset)
   (add-hook 'kill-emacs-hook '+circe-quit-all@kill-emacs))
 
 (setup (:straight consult)
@@ -662,7 +652,8 @@ See also `crux-reopen-as-root-mode'."
   (require 'modus-themes (.etc "straight/build/modus-themes/modus-themes"))
   (:option modus-themes-bold-constructs t
            modus-themes-italic-constructs t
-           modus-themes-headings '((t . (background)))))
+           modus-themes-headings '((t . (background))))
+  (+sunrise-sunset 'modus-themes-load-operandi 'modus-themes-load-vivendi))
 
 (setup (:straight mwim)
   (:+key "C-a" #'mwim-beginning
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