aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-13 16:14:50 -0500
committerCraig Jennings <c@cjennings.net>2026-05-13 16:14:50 -0500
commit79ee1a9e9bddf0a7be61913840e0c74d7edea66f (patch)
tree92f2ad6bac51281ec4150f37b6e612b628abf4fc
parentb13b82a771a3bae7f020919d4e1ab0597f6cc4ab (diff)
downloaddotemacs-79ee1a9e9bddf0a7be61913840e0c74d7edea66f.tar.gz
dotemacs-79ee1a9e9bddf0a7be61913840e0c74d7edea66f.zip
refactor(org-agenda): extract main-agenda prefix format into a defvar
`org-agenda-custom-commands` inlined ` %i %-15:c%?-15t% s` four times across the "d" command's overdue / high-priority / schedule / priority-B blocks. New `cj/--main-agenda-prefix-format` defvar holds the literal once; every block now references the symbol so a format tweak lands in one place. Regression test walks the "d" command's blocks and asserts each `org-agenda-prefix-format` cell resolves to the shared symbol -- a block that silently diverges fails the check.
-rw-r--r--modules/org-agenda-config.el14
-rw-r--r--tests/test-org-agenda-config-skip-functions.el17
2 files changed, 27 insertions, 4 deletions
diff --git a/modules/org-agenda-config.el b/modules/org-agenda-config.el
index 2c30db0fe..9ff2fd722 100644
--- a/modules/org-agenda-config.el
+++ b/modules/org-agenda-config.el
@@ -279,6 +279,12 @@ If the current buffer isn't an org buffer, inform the user."
(defvar cj/main-agenda-tasks-title "PRIORITY B"
"String to announce the schedule section of the main agenda.")
+(defvar cj/--main-agenda-prefix-format " %i %-15:c%?-15t% s"
+ "Prefix format string shared by all blocks of the main daily agenda.
+Inlined across the overdue / high-priority / schedule / priority-B
+blocks of `org-agenda-custom-commands' before the extraction. Keep
+the four blocks pointing here so a format tweak lands in one place.")
+
(defun cj/org-skip-subtree-if-habit ()
"Skip an agenda entry if it has a STYLE property equal to \"habit\"."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
@@ -331,11 +337,11 @@ KEYWORDS must be a list of strings."
((alltodo ""
((org-agenda-skip-function #'cj/org-agenda-skip-subtree-if-not-overdue)
(org-agenda-overriding-header cj/main-agenda-overdue-title)
- (org-agenda-prefix-format " %i %-15:c%?-15t% s")))
+ (org-agenda-prefix-format cj/--main-agenda-prefix-format)))
(tags "PRIORITY=\"A\""
((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
(org-agenda-overriding-header cj/main-agenda-hipri-title)
- (org-agenda-prefix-format " %i %-15:c%?-15t% s")))
+ (org-agenda-prefix-format cj/--main-agenda-prefix-format)))
(agenda ""
((org-agenda-start-day "0d")
(org-agenda-span 8)
@@ -345,7 +351,7 @@ KEYWORDS must be a list of strings."
(org-agenda-skip-function
'(org-agenda-skip-entry-if 'todo '("CANCELLED")))
(org-agenda-overriding-header cj/main-agenda-schedule-title)
- (org-agenda-prefix-format " %i %-15:c%?-15t% s")))
+ (org-agenda-prefix-format cj/--main-agenda-prefix-format)))
(alltodo ""
((org-agenda-skip-function '(or (cj/org-skip-subtree-if-habit)
(cj/org-skip-subtree-if-priority ?A)
@@ -354,7 +360,7 @@ KEYWORDS must be a list of strings."
(cj/org-skip-subtree-if-keyword '("PROJECT"))
(org-agenda-skip-if nil '(scheduled deadline))))
(org-agenda-overriding-header cj/main-agenda-tasks-title)
- (org-agenda-prefix-format " %i %-15:c%?-15t% s"))))
+ (org-agenda-prefix-format cj/--main-agenda-prefix-format))))
((org-agenda-compact-blocks nil)))))
diff --git a/tests/test-org-agenda-config-skip-functions.el b/tests/test-org-agenda-config-skip-functions.el
index 17ee848f3..3c044adbd 100644
--- a/tests/test-org-agenda-config-skip-functions.el
+++ b/tests/test-org-agenda-config-skip-functions.el
@@ -247,5 +247,22 @@ priority-B blocks must not pick up the same skip-function form."
(skip (cadr (assoc 'org-agenda-skip-function opts))))
(should-not (equal skip cancelled-form))))))
+;;; ---------- prefix-format extracted into a defvar ----------
+
+;;; Normal Cases
+
+(ert-deftest test-org-agenda-config-prefix-format-extracted-to-defvar ()
+ "Normal: every block of the \"d\" command references the shared prefix
+format symbol rather than inlining the literal string. Catches a
+regression where one block diverges from the others on the format."
+ (let* ((entry (assoc "d" org-agenda-custom-commands))
+ (blocks (nth 2 entry)))
+ (should (boundp 'cj/--main-agenda-prefix-format))
+ (should (stringp cj/--main-agenda-prefix-format))
+ (dolist (b blocks)
+ (let* ((opts (nth 2 b))
+ (fmt-form (cadr (assoc 'org-agenda-prefix-format opts))))
+ (should (eq fmt-form 'cj/--main-agenda-prefix-format))))))
+
(provide 'test-org-agenda-config-skip-functions)
;;; test-org-agenda-config-skip-functions.el ends here