From 266a660cb8db190e0418c5f7062af95e1a31270f Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 14 May 2026 07:18:11 -0500 Subject: 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. --- tests/test-org-roam-config-copy-and-move.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/test-org-roam-config-copy-and-move.el b/tests/test-org-roam-config-copy-and-move.el index 7925da2b..729afaa8 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)." -- cgit v1.2.3