diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-05 06:01:13 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-05 06:01:13 -0500 |
| commit | ecfc66294e57788df715c98297ef425fd9dbd9ef (patch) | |
| tree | 0142d54735b4a778bad0babc5d55dad18f624469 | |
| parent | 877c104bfa8497324de45b2fef96dd4520da07e4 (diff) | |
| download | pearl-ecfc66294e57788df715c98297ef425fd9dbd9ef.tar.gz pearl-ecfc66294e57788df715c98297ef425fd9dbd9ef.zip | |
feat(render): save the buffer to disk after a fetch or refresh
The full-replace render saved the Org file, but the in-place paths didn't, so a refresh or a comment fetch left the buffer modified-but-unsaved and the file on disk stale. Five paths now save through pearl--save-if-visiting: refresh-current-view, refresh-current-issue, fetch-all-comments, create-comment, and the merge branch of a dirty source-switch.
The helper saves only when the buffer visits a file, so it's a no-op in a test buffer. Saving the Org file never pushes to Linear, so an unpushed edit still waits for pearl-save-issue. This only keeps the disk copy in step with what's on screen. fetch-all-comments surfaced the gap first. An audit turned up the other four.
| -rw-r--r-- | pearl.el | 19 | ||||
| -rw-r--r-- | tests/test-pearl-fetch-all-comments.el | 25 |
2 files changed, 42 insertions, 2 deletions
@@ -3529,6 +3529,8 @@ proceeds and the subtree is replaced with Linear's version." (pearl--replace-issue-subtree-at-point (pearl--normalize-issue raw))) (pearl-highlight-comments) + (with-current-buffer (marker-buffer marker) + (pearl--save-if-visiting)) (pearl--surface-buffer (marker-buffer marker)) (message "Refreshed %s from Linear" issue-id)) (message "Refreshed %s; its buffer was closed" issue-id)))))))))) @@ -3627,7 +3629,8 @@ create callback fires with another buffer current (the compose path)." (save-excursion (goto-char marker) (pearl--append-comment-to-issue comment)) - (pearl-highlight-comments)) + (pearl-highlight-comments) + (pearl--save-if-visiting)) (pearl--surface-buffer buf))) (message "Added comment to %s" issue-id))))) @@ -3729,7 +3732,8 @@ those first." (save-excursion (goto-char marker) (pearl--replace-comments-subtree comments)) - (pearl-highlight-comments)) + (pearl-highlight-comments) + (pearl--save-if-visiting)) (pearl--surface-buffer buf) (message "Fetched all %d comment%s for %s" (length comments) @@ -4196,6 +4200,15 @@ as a malformed plist and breaks refresh and sort." (let ((print-length nil) (print-level nil)) (prin1-to-string source))) +(defun pearl--save-if-visiting () + "Save the current buffer to its file when it visits one. +A no-op in a non-file buffer. A fetch/refresh renders Linear's data into the +file-backed Pearl buffer; saving keeps the file in step with what's on screen, +the way the full-replace render already does. Saving the Org file never pushes +to Linear -- a local edit still needs `pearl-save-issue' -- so this only syncs +the disk copy." + (when buffer-file-name (save-buffer))) + (defun pearl--build-org-content (issues &optional source truncated states account) "Build the Org content string for the linear org file from ISSUES. SOURCE is the active-source descriptor recorded in the header so a later @@ -4359,6 +4372,7 @@ just writing the file and leaving it off-screen." ;; edit-then-merge flow doesn't collapse the subtree they were ;; editing. (pearl--fold-touched-subtrees (plist-get counts :touched-markers)) + (pearl--save-if-visiting) (message "Merged into %s: %d updated, %d added, %d dropped%s" (file-name-nondirectory org-file-path) (plist-get counts :updated) @@ -6733,6 +6747,7 @@ of the replace path." ;; Same as the dirty-merge path: fold only the touched subtrees, leave ;; the rest of the page and point alone. (pearl--fold-touched-subtrees (plist-get counts :touched-markers)) + (pearl--save-if-visiting) (pearl--surface-buffer (current-buffer)) (message "Refreshed %s: %d updated, %d added, %d dropped%s" (pearl--source-name source) diff --git a/tests/test-pearl-fetch-all-comments.el b/tests/test-pearl-fetch-all-comments.el index 04dfe31..4449314 100644 --- a/tests/test-pearl-fetch-all-comments.el +++ b/tests/test-pearl-fetch-all-comments.el @@ -124,5 +124,30 @@ (test-pearl-fac--goto-issue) (should-not (pearl--unpushed-comment-edits-p)))) +;;; save-after-fetch helper + +(ert-deftest test-pearl-save-if-visiting-noop-without-file () + "In a non-file buffer the save helper is a no-op, not an error." + (with-temp-buffer + (insert "x") + (should-not (pearl--save-if-visiting)))) + +(ert-deftest test-pearl-save-if-visiting-saves-file-buffer () + "In a file-visiting buffer the helper writes the buffer to disk." + (let ((f (make-temp-file "pearl-save-" nil ".org"))) + (unwind-protect + (let ((buf (find-file-noselect f))) + (unwind-protect + (with-current-buffer buf + (insert "hello pearl") + (should (buffer-modified-p)) + (pearl--save-if-visiting) + (should-not (buffer-modified-p)) + (should (string-match-p + "hello pearl" + (with-temp-buffer (insert-file-contents f) (buffer-string))))) + (kill-buffer buf))) + (delete-file f)))) + (provide 'test-pearl-fetch-all-comments) ;;; test-pearl-fetch-all-comments.el ends here |
