aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-30 09:09:15 -0500
committerCraig Jennings <c@cjennings.net>2026-07-30 09:09:15 -0500
commitce223dc63c4901603e66aab0ebc8934791260c89 (patch)
tree84b7d2f2a2583f7cfc4e9090629b77e29d4f00cd /modules
parent204bc6091b76c30e68a14cd2c3b948179b27c602 (diff)
downloaddotemacs-ce223dc63c4901603e66aab0ebc8934791260c89.tar.gz
dotemacs-ce223dc63c4901603e66aab0ebc8934791260c89.zip
fix(agenda): make the project-name category actually apply
- The override never fired once since it shipped. - Its guard wanted org-category to already equal "todo". - Org leaves that nil and derives the name later. - So the condition was false in every real buffer. The guard now tests for nil, and the hook runs at depth -100. That depth is load-bearing. org-get-category resolves a deferred value the element cache then holds, so any hook reading it first freezes "todo" and leaves the override inert. add-hook prepends, and three hooks already run ahead. The old tests set org-category by hand to a value org never produces, so they passed while the feature did nothing. They now visit real files and assert on what the agenda reads. The two todo.org agenda files show their project name. Files with distinctive names keep theirs, and an explicit category still wins.
Diffstat (limited to 'modules')
-rw-r--r--modules/org-agenda-config.el22
1 files changed, 16 insertions, 6 deletions
diff --git a/modules/org-agenda-config.el b/modules/org-agenda-config.el
index 599a8abf..20714d5d 100644
--- a/modules/org-agenda-config.el
+++ b/modules/org-agenda-config.el
@@ -199,17 +199,27 @@ nil so the org default category applies."
(defun cj/--org-set-todo-category ()
"Set buffer-local `org-category' to the project name for a todo.org buffer.
-Runs from `org-mode-hook'. Only overrides when `org-category' is still
-the default-from-filename (\"todo\"), so an explicit `#+CATEGORY:' in
-the file keeps precedence."
+Runs from `org-mode-hook'. Only overrides when nothing has set
+`org-category', so an explicit `#+CATEGORY:' in the file keeps precedence.
+
+The nil test is the whole guard, and it took a while to get right. Org does
+not assign the filename fallback to `org-category': with no `#+CATEGORY:' the
+variable stays nil and `org-get-category' derives \"todo\" at read time. An
+earlier version guarded on `(string= \"todo\" org-category)', which is a state
+org never produces, so this hook did nothing from the day it shipped."
(when (and buffer-file-name
(boundp 'org-category)
- (stringp org-category)
- (string= "todo" org-category))
+ (null org-category))
(when-let* ((project (cj/--org-todo-category-from-file buffer-file-name)))
(setq-local org-category project))))
-(add-hook 'org-mode-hook #'cj/--org-set-todo-category)
+;; Depth -100 so this runs FIRST, and it is load-bearing. `org-get-category'
+;; resolves a deferred `:CATEGORY' that the org-element cache then holds, so any
+;; hook that reads the category before this one freezes "todo" in that cache and
+;; leaves the `setq-local' below inert -- `org-category' reads correct while the
+;; agenda still shows "todo". `add-hook' prepends by default, so without the
+;; depth every hook added later would run earlier, and three already do.
+(add-hook 'org-mode-hook #'cj/--org-set-todo-category -100)
;; ------------------------ Org Agenda File List Cache -------------------------
;; Cache agenda file list to avoid expensive directory scanning on every view.