aboutsummaryrefslogtreecommitdiff
path: root/chime-debug.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-02-17 00:11:56 -0600
committerCraig Jennings <c@cjennings.net>2026-02-17 00:11:56 -0600
commit3e8d0f571af146e3d234ce1ab55f0f746d522fe7 (patch)
treed4aa3f8e293e77a175fcf077cd7a6e3b76c44768 /chime-debug.el
parent30cf2bfe06d443da1ff41ab9bddc4bd6a431aa5f (diff)
downloadchime-3e8d0f571af146e3d234ce1ab55f0f746d522fe7.tar.gz
chime-3e8d0f571af146e3d234ce1ab55f0f746d522fe7.zip
Add notification filtering debugger to chime-debug.el
Interactive function chime--debug-notification-filtering traces the entire notification pipeline: timestamp recognition, day-wide filtering, interval matching, and notification generation. Helps diagnose why notifications aren't firing for specific events.
Diffstat (limited to 'chime-debug.el')
-rw-r--r--chime-debug.el124
1 files changed, 124 insertions, 0 deletions
diff --git a/chime-debug.el b/chime-debug.el
index 657d218..ca6855b 100644
--- a/chime-debug.el
+++ b/chime-debug.el
@@ -370,5 +370,129 @@ Shows loaded features before the check and logs async process details."
(message "Chime: Forced check initiated - see *Messages* for details"))
+;;; Notification Filtering Debugger
+
+;;;###autoload
+(defun chime--debug-notification-filtering (event-time interval)
+ "Debug why a notification might not be generated for EVENT-TIME and INTERVAL.
+EVENT-TIME should be an Emacs time value (from encode-time or current-time).
+INTERVAL is the number of minutes before the event to notify.
+
+This function traces through the entire notification filtering pipeline:
+1. Timestamp string generation
+2. Day-wide event filtering (chime--has-timestamp)
+3. Table-flat combination generation
+4. Timestamp-within-interval-p matching
+
+Example usage:
+ (chime--debug-notification-filtering
+ (time-add (current-time) (seconds-to-time (* 4 24 3600))) ; 4 days from now
+ 5760) ; 4 days in minutes
+
+Or for a specific date/time:
+ (chime--debug-notification-filtering
+ (encode-time 0 0 10 22 11 2025) ; Nov 22, 2025 at 10:00
+ 10) ; 10 minutes before"
+ (interactive
+ (let* ((days (read-number "Days from now: " 0))
+ (hours (read-number "Additional hours: " 0))
+ (minutes (read-number "Additional minutes: " 10))
+ (total-seconds (+ (* days 86400) (* hours 3600) (* minutes 60)))
+ (event-time (time-add (current-time) (seconds-to-time total-seconds)))
+ (interval (read-number "Notification interval (minutes): " 10)))
+ (list event-time interval)))
+
+ (let* ((timestamp-str (format-time-string "<%Y-%m-%d %a %H:%M>" event-time))
+ (now (current-time))
+ (event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Debug Test Event")
+ (intervals . ((,interval . medium))))))
+
+ (chime--log-silently "\n=== Chime Debug: Notification Filtering ===")
+ (chime--log-silently "Current time: %s"
+ (format-time-string "%Y-%m-%d %H:%M:%S" now))
+ (chime--log-silently "Event time: %s"
+ (format-time-string "%Y-%m-%d %H:%M:%S" event-time))
+ (chime--log-silently "Interval: %d minutes" interval)
+ (chime--log-silently "Timestamp: %s" timestamp-str)
+
+ ;; Calculate time differences
+ (let* ((seconds-until (float-time (time-subtract event-time now)))
+ (minutes-until (/ seconds-until 60.0))
+ (hours-until (/ minutes-until 60.0))
+ (days-until (/ hours-until 24.0)))
+ (chime--log-silently "\nTime until event:")
+ (chime--log-silently " %.2f seconds (%.2f minutes, %.2f hours, %.2f days)"
+ seconds-until minutes-until hours-until days-until))
+
+ ;; Step 1: Check timestamp recognition
+ (chime--log-silently "\n--- Step 1: Timestamp Recognition ---")
+ (let ((has-time (chime--has-timestamp timestamp-str)))
+ (chime--log-silently "chime--has-timestamp: %s" has-time)
+ (when (string-match org-ts-regexp0 timestamp-str)
+ (chime--log-silently "org-ts-regexp0 matches: yes")
+ (chime--log-silently "match-beginning 7 (time component): %s"
+ (match-beginning 7)))
+ (unless has-time
+ (chime--log-silently "⚠ WARNING: Timestamp not recognized as having time component!")
+ (chime--log-silently " This event would be filtered out by chime--filter-day-wide-events")))
+
+ ;; Step 2: Check time equality
+ (chime--log-silently "\n--- Step 2: Time Matching ---")
+ (let* ((check-time (time-add now (seconds-to-time (* 60 interval))))
+ (check-time-str (format-time-string "%Y-%m-%d %H:%M:%S" check-time))
+ (event-time-str (format-time-string "%Y-%m-%d %H:%M:%S" event-time))
+ (matches (chime--time= check-time event-time)))
+ (chime--log-silently "Current time + interval: %s" check-time-str)
+ (chime--log-silently "Event time: %s" event-time-str)
+ (chime--log-silently "chime--time= result: %s" matches)
+
+ ;; Show the formatted strings that chime--time= compares
+ (chime--log-silently "\nFormatted comparison strings:")
+ (chime--log-silently " Current + interval: %s"
+ (format-time-string "%Y-%m-%d %H:%M" check-time))
+ (chime--log-silently " Event time: %s"
+ (format-time-string "%Y-%m-%d %H:%M" event-time))
+
+ (unless matches
+ (chime--log-silently "⚠ Times do not match - notification would NOT be generated")
+ (let ((diff-seconds (abs (float-time (time-subtract check-time event-time)))))
+ (chime--log-silently " Time difference: %.0f seconds (%.2f minutes)"
+ diff-seconds (/ diff-seconds 60.0)))))
+
+ ;; Step 3: Test chime--timestamp-within-interval-p
+ (chime--log-silently "\n--- Step 3: chime--timestamp-within-interval-p ---")
+ (let ((result (chime--timestamp-within-interval-p event-time interval)))
+ (chime--log-silently "Result: %s" result)
+ (if result
+ (chime--log-silently "✓ Event is within notification interval")
+ (chime--log-silently "✗ Event is NOT within notification interval")))
+
+ ;; Step 4: Test chime--notifications
+ (chime--log-silently "\n--- Step 4: chime--notifications (full pipeline) ---")
+ (let* ((times (cdr (assoc 'times event)))
+ (intervals (cdr (assoc 'intervals event)))
+ (filtered-times (chime--filter-day-wide-events times))
+ (result (chime--notifications event)))
+ (chime--log-silently "Input times: %d" (length times))
+ (chime--log-silently "After day-wide filter: %d" (length filtered-times))
+ (chime--log-silently "Final notifications: %d" (length result))
+
+ (if (> (length result) 0)
+ (progn
+ (chime--log-silently "✓ Notification WOULD be generated")
+ (dolist (notif result)
+ (chime--log-silently " Message: %s" (car notif))
+ (chime--log-silently " Severity: %s" (cdr notif))))
+ (chime--log-silently "✗ Notification would NOT be generated")
+ (chime--log-silently "\nPossible reasons:")
+ (when (= (length filtered-times) 0)
+ (chime--log-silently " - Timestamp filtered out as day-wide event"))
+ (when (not (chime--timestamp-within-interval-p event-time interval))
+ (chime--log-silently " - Event not within %d-minute interval" interval))))
+
+ (chime--log-silently "=== End Chime Debug ===\n")
+ (message "Chime: Notification filtering debug complete - see *Messages*")))
+
(provide 'chime-debug)
;;; chime-debug.el ends here