From ecfc66294e57788df715c98297ef425fd9dbd9ef Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 5 Jun 2026 06:01:13 -0500 Subject: 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. --- pearl.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'pearl.el') diff --git a/pearl.el b/pearl.el index a24d7dd..880e7ed 100644 --- a/pearl.el +++ b/pearl.el @@ -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) -- cgit v1.2.3