aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 07:18:11 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 07:18:11 -0500
commitf67b6917c3356a12ca191393c7da038bb1586d76 (patch)
tree6f6ef3f701826fe92150af25b1531c94d4fadf80
parent401e06ddb4b70e066667a66d49d9c67eba578269 (diff)
downloaddotemacs-f67b6917c3356a12ca191393c7da038bb1586d76.tar.gz
dotemacs-f67b6917c3356a12ca191393c7da038bb1586d76.zip
fix(org-roam-config): save journal buffer after copying DONE task
`cj/org-roam-copy-todo-to-today' tried to save the target journal buffer via `org-after-refile-insert-hook' bound to `#'save-buffer', but that value is the wrong shape (single function instead of a hook list), and the only other save mechanism -- the `:after' advice on `org-refile' that calls `org-save-all-org-buffers' -- doesn't attach until `:defer .5' elapses, so the very first DONE transition after startup leaves the journal unsaved. Drop the broken hook binding and save the target buffer explicitly after the refile call. New ERT test asserts `buffer-modified-p' on the journal buffer is nil after the function returns.
-rw-r--r--modules/org-roam-config.el7
-rw-r--r--tests/test-org-roam-config-copy-and-move.el28
2 files changed, 33 insertions, 2 deletions
diff --git a/modules/org-roam-config.el b/modules/org-roam-config.el
index 3f011c9d3..52c41127c 100644
--- a/modules/org-roam-config.el
+++ b/modules/org-roam-config.el
@@ -170,7 +170,6 @@ created in that subdirectory of `org-roam-directory'."
:if-new (file+head+olp "%<%Y-%m-%d>.org"
"#+FILETAGS: Journal
#+TITLE: %<%Y-%m-%d>\n" ("Completed Tasks")))))
- (org-after-refile-insert-hook #'save-buffer)
today-file
pos)
(save-window-excursion
@@ -181,7 +180,11 @@ created in that subdirectory of `org-roam-directory'."
;; Only refile if the target file is different than the current file
(unless (equal (file-truename today-file)
(file-truename (buffer-file-name)))
- (org-refile nil nil (list "Completed Tasks" today-file nil pos)))))
+ (org-refile nil nil (list "Completed Tasks" today-file nil pos))
+ ;; Save explicitly so shutdown doesn't prompt about an unsaved journal buffer.
+ (when-let ((target-buffer (find-buffer-visiting today-file)))
+ (with-current-buffer target-buffer
+ (save-buffer))))))
;; ------------------------ Org-Branch To Org-Roam-Node ------------------------
diff --git a/tests/test-org-roam-config-copy-and-move.el b/tests/test-org-roam-config-copy-and-move.el
index 7925da2b9..729afaa8b 100644
--- a/tests/test-org-roam-config-copy-and-move.el
+++ b/tests/test-org-roam-config-copy-and-move.el
@@ -57,6 +57,34 @@ when today-file differs from the current buffer file."
(delete-file source)
(delete-file today))))
+(ert-deftest test-org-roam-copy-todo-saves-target-buffer ()
+ "Normal: after the refile into today's journal, the target buffer
+must not be left modified. An unsaved journal buffer is what causes
+Emacs to prompt about unsaved buffers at shutdown."
+ (let ((source (make-temp-file "cj-roam-source-" nil ".org"))
+ (today (make-temp-file "cj-roam-today-" nil ".org")))
+ (unwind-protect
+ (with-temp-buffer
+ (setq buffer-file-name source)
+ (cl-letf (((symbol-function 'org-roam-dailies--capture)
+ (lambda (&rest _)
+ (set-buffer (find-file-noselect today))
+ (goto-char (point-max))))
+ ((symbol-function 'org-refile)
+ (lambda (&rest _)
+ ;; Simulate org-refile inserting into the
+ ;; target buffer (which marks it modified).
+ (with-current-buffer (find-file-noselect today)
+ (goto-char (point-max))
+ (insert "* refiled content\n")))))
+ (cj/org-roam-copy-todo-to-today))
+ (let ((target-buffer (find-buffer-visiting today)))
+ (should target-buffer)
+ (should-not (buffer-modified-p target-buffer))))
+ (when (get-file-buffer today) (kill-buffer (get-file-buffer today)))
+ (delete-file source)
+ (delete-file today))))
+
(ert-deftest test-org-roam-copy-todo-skips-when-already-today ()
"Boundary: when the current buffer already visits today's file, no
refile is issued (same source and target)."