aboutsummaryrefslogtreecommitdiff
path: root/chime.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 13:07:26 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 13:07:26 -0500
commitd09da430bf1fa08bb089b4386b6284879088260b (patch)
tree3c5e1967d45ee4792a4e55ca88b246c3037023ca /chime.el
parent3c95c690d18ced45b919283114077a4f6ecd0fe9 (diff)
downloadchime-d09da430bf1fa08bb089b4386b6284879088260b.tar.gz
chime-d09da430bf1fa08bb089b4386b6284879088260b.zip
Extract validation retry logic from chime-check into chime--maybe-validate
The validation/retry state machine was 30 lines embedded in chime-check. Now chime--maybe-validate returns t if OK to proceed, nil to skip. chime-check is reduced to 12 lines: validate, then fetch-and-process.
Diffstat (limited to 'chime.el')
-rw-r--r--chime.el51
1 files changed, 25 insertions, 26 deletions
diff --git a/chime.el b/chime.el
index 582d61a..d7ea12e 100644
--- a/chime.el
+++ b/chime.el
@@ -1799,29 +1799,17 @@ FORMAT-STRING and ARGS are passed to `format'."
(insert (apply #'format format-string args))
(unless (bolp) (insert "\n")))))
-;;;###autoload
-(cl-defun chime-check ()
- "Parse agenda view and notify about upcoming events.
-
-Do nothing if a check is already in progress in the background.
-
-On the first call after `chime-mode' is enabled, validates the runtime
-configuration. This happens after `chime-startup-delay', giving startup
-hooks time to populate org-agenda-files. If validation fails, logs an
-error and skips the check."
- (interactive)
-
- ;; Validate configuration on first check only
- (unless chime--validation-done
+(defun chime--maybe-validate ()
+ "Run startup validation if not yet done. Return t if OK to proceed.
+Handles retry logic for async org-agenda-files initialization.
+Returns nil if validation failed and check should be skipped."
+ (if chime--validation-done
+ t
(let ((issues (chime-validate-configuration)))
(if (cl-some (lambda (i) (eq (car i) :error)) issues)
(progn
- ;; Critical errors found - increment retry counter
(setq chime--validation-retry-count (1+ chime--validation-retry-count))
-
- ;; Check if we've exceeded max retries
(if (> chime--validation-retry-count chime-validation-max-retries)
- ;; Max retries exceeded - show full error
(let ((errors (cl-remove-if-not (lambda (i) (eq (car i) :error)) issues)))
(chime--log-silently "Chime: Configuration validation failed with %d error(s) after %d retries:"
(length errors)
@@ -1830,18 +1818,29 @@ error and skips the check."
(chime--log-silently "")
(chime--log-silently "ERROR: %s" (cadr err)))
(message "Chime: Configuration errors detected (see *Messages* buffer for details)"))
- ;; Still within retry limit - show friendly waiting message
(message "Chime: Waiting for org-agenda-files to load... (attempt %d/%d)"
chime--validation-retry-count
chime-validation-max-retries))
-
- ;; Don't mark validation as done - will retry on next check
- ;; in case dependencies load later
- ;; Don't proceed with check
- (cl-return-from chime-check nil))
- ;; No errors - mark validation as done and reset retry counter
+ nil)
(setq chime--validation-done t)
- (setq chime--validation-retry-count 0))))
+ (setq chime--validation-retry-count 0)
+ t))))
+
+;;;###autoload
+(cl-defun chime-check ()
+ "Parse agenda view and notify about upcoming events.
+
+Do nothing if a check is already in progress in the background.
+
+On the first call after `chime-mode' is enabled, validates the runtime
+configuration. This happens after `chime-startup-delay', giving startup
+hooks time to populate org-agenda-files. If validation fails, logs an
+error and skips the check."
+ (interactive)
+
+ ;; Validate configuration on first check only
+ (unless (chime--maybe-validate)
+ (cl-return-from chime-check nil))
;; Validation passed or already done - proceed with check
(chime--fetch-and-process