summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-26 00:16:54 -0500
committerCraig Jennings <c@cjennings.net>2025-10-26 00:16:54 -0500
commit0418ccd93b2e9224de41db461a1a41f8658c6ec5 (patch)
tree523accff76b6d7c25a7ac39375d534fcade8b1be /modules
parent7f7c8bb51fc745ee1eaf8d7fa01b67c7dde8e722 (diff)
fix:org-roam: copy completed tasks to dailies on state transitions
Fixed and enhanced the org-roam hook that copies completed tasks to daily notes: - Fixed hook not triggering immediately after Emacs launch by moving it outside the lazy-loaded use-package org-roam :config block and into with-eval-after-load 'org - Changed hook to trigger for ANY org-done-keyword (DONE, CANCELLED, etc.) instead of just "DONE" - Updated hook to only trigger on non-done → done transitions using org-last-state, preventing duplicate copies when changing between done states (e.g., DONE → CANCELLED) - Added docstrings to org-roam helper functions to fix checkdoc linter warnings - Created comprehensive ERT test suite with 10 tests covering: * Hook registration before org-roam loads (lazy-loading fix) * Transitions to done states (nil→DONE, TODO→DONE, IN-PROGRESS→DONE, WAITING→CANCELLED) * Non-triggering cases (done→done, transitions to non-done states)
Diffstat (limited to 'modules')
-rw-r--r--modules/org-roam-config.el34
1 files changed, 20 insertions, 14 deletions
diff --git a/modules/org-roam-config.el b/modules/org-roam-config.el
index c497fd4b..18552b1d 100644
--- a/modules/org-roam-config.el
+++ b/modules/org-roam-config.el
@@ -69,15 +69,17 @@
;; remove/disable if performance slows
;; (setq org-element-use-cache nil) ;; disables caching org files
- ;; move closed tasks to today's journal when marked done
- (add-to-list 'org-after-todo-state-change-hook
- (lambda ()
- (when (equal org-state "DONE")
- (cj/org-roam-copy-todo-to-today))))
-
(require 'org-roam-dailies) ;; Ensures the keymap is available
(org-roam-db-autosync-mode))
+;; Move closed tasks to today's journal when marked done
+(with-eval-after-load 'org
+ (add-to-list 'org-after-todo-state-change-hook
+ (lambda ()
+ (when (and (member org-state org-done-keywords)
+ (not (member org-last-state org-done-keywords)))
+ (cj/org-roam-copy-todo-to-today)))))
+
;; ------------------------- Org Roam Insert Immediate -------------------------
(defun cj/org-roam-node-insert-immediate (arg &rest args)
@@ -95,10 +97,12 @@ the arguments that org-roam-node-insert expects."
;; ------------------------- Tag Listing And Filtering -------------------------
(defun cj/org-roam-filter-by-tag (tag-name)
+ "Return a predicate function that filters org-roam nodes by TAG-NAME."
(lambda (node)
(member tag-name (org-roam-node-tags node))))
(defun cj/org-roam-list-notes-by-tag (tag-name)
+ "Return a list of file paths for all org-roam nodes tagged with TAG-NAME."
(mapcar #'org-roam-node-file
(seq-filter
(cj/org-roam-filter-by-tag tag-name)
@@ -106,12 +110,12 @@ the arguments that org-roam-node-insert expects."
;; -------------------------- Org Roam Find Functions --------------------------
-;;;###autoload
(defun cj/org-roam-find-node (tag template-key template-file &optional subdir)
"List all nodes of type TAG in completing read for selection or creation.
Interactively find or create an Org-roam node with a given TAG. Newly
created nodes are added to the agenda and follow a template defined by
-TEMPLATE-KEY and TEMPLATE-FILE."
+TEMPLATE-KEY and TEMPLATE-FILE. If SUBDIR is provided, new nodes are
+created in that subdirectory of `org-roam-directory'."
(interactive)
(add-hook 'org-capture-after-finalize-hook
#'cj/org-roam-add-node-to-agenda-files-finalize-hook)
@@ -122,14 +126,15 @@ TEMPLATE-KEY and TEMPLATE-FILE."
:if-new (file+head ,(concat (or subdir "") "%<%Y%m%d%H%M%S>-${slug}.org") "")
:unnarrowed t))))
-;;;###autoload
+
(defun cj/org-roam-find-node-topic ()
- "List nodes of type \=`topic\=` in completing read for selection or creation."
+ "List nodes of type \=`Topic\=` in completing read for selection or creation."
(interactive)
(cj/org-roam-find-node "Topic" "t" (concat roam-dir "templates/topic.org")))
-;;;###autoload
+
(defun cj/org-roam-find-node-recipe ()
+ "List nodes of type \"Recipe\" in completing read for selection or creation."
(interactive)
(cj/org-roam-find-node "Recipe" "r" (concat roam-dir "templates/recipe.org") "recipes/"))
@@ -185,12 +190,13 @@ Otherwise return TEXT unchanged."
(or description url))
text))
-;;;###autoload
+
(defun cj/move-org-branch-to-roam ()
"Move the org subtree at point to a new org-roam node.
The node filename will be timestamp-based with the heading name.
-The heading becomes the node title, and the entire subtree is demoted to level 1.
-If the heading contains a link, extract the description for the title."
+The heading becomes the node title, and the entire subtree is demoted to
+level 1. If the heading contains a link, extract the description for the
+title."
(interactive)
;; Lazy load org and org-roam when needed
(require 'org)