aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pearl.el19
-rw-r--r--tests/test-pearl-fetch-all-comments.el25
2 files changed, 42 insertions, 2 deletions
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)
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