From f07ce74d835dfc81e1e529240526829464ad8b21 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 22 May 2026 19:43:00 -0500 Subject: fix(org-roam): always save the daily after a journal task-copy The save lived inside the `unless` branch that only ran when the completed task needed an `org-refile` into a different file. When the task was already in today's daily, the copy left the buffer modified but unsaved. A crash before the next manual save lost it, and shutdown prompted about the unsaved journal buffer. I pulled the save out of the refile branch into a `cj/--org-roam-save-daily` helper that runs on both paths and only writes when the buffer is modified. Extracting it also makes the save logic testable without driving the org-roam capture machinery. --- modules/org-roam-config.el | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/org-roam-config.el b/modules/org-roam-config.el index 306c7fe2..0382976b 100644 --- a/modules/org-roam-config.el +++ b/modules/org-roam-config.el @@ -185,6 +185,15 @@ created in that subdirectory of `org-roam-directory'." ;; ------------------------ Org Roam Copy Done To Daily ------------------------ +(defun cj/--org-roam-save-daily (file) + "Save FILE's visiting buffer when it has unsaved changes. +Keeps a freshly-copied task off the unsaved-buffer prompt at shutdown and +guards against losing it to a crash." + (when-let ((target-buffer (find-buffer-visiting file))) + (with-current-buffer target-buffer + (when (buffer-modified-p) + (save-buffer))))) + (defun cj/org-roam-copy-todo-to-today () "Copy completed tasks to today's daily org-roam node." (interactive) @@ -204,11 +213,10 @@ 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)) - ;; 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-refile nil nil (list "Completed Tasks" today-file nil pos))) + + ;; Save the daily whether or not a refile happened, so the copy survives. + (cj/--org-roam-save-daily today-file))) ;; ------------------------ Org-Branch To Org-Roam-Node ------------------------ -- cgit v1.2.3