diff options
| -rw-r--r-- | modules/org-roam-config.el | 7 | ||||
| -rw-r--r-- | tests/test-org-roam-config-copy-and-move.el | 28 |
2 files changed, 33 insertions, 2 deletions
diff --git a/modules/org-roam-config.el b/modules/org-roam-config.el index 3f011c9d..52c41127 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 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)." |
