From 5b47adb978eeeb241605e99c06815f44d9bfad5b Mon Sep 17 00:00:00 2001 From: Lucas Sta Maria Date: Sat, 23 Aug 2025 22:39:25 +0800 Subject: [PATCH] fix: enable editable review buffer --- ghpr-review.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ghpr-review.el b/ghpr-review.el index eafecf9..03d91bd 100644 --- a/ghpr-review.el +++ b/ghpr-review.el @@ -57,6 +57,9 @@ (0 'ghpr-review-removed-line t))) "Font lock keywords for ghpr-review-mode.") +(defvar-local ghpr-review-diff-content nil + "Buffer-local variable storing the diff content for the current PR.") + (define-derived-mode ghpr-review-mode text-mode "GHPR Review" "Major mode for reviewing GitHub pull requests." :group 'ghpr @@ -72,22 +75,23 @@ (let ((lines (split-string text "\n"))) (mapconcat #'ghpr--prefix-line lines "\n"))) -(defun ghpr--open-pr/collect-contents (pr repo-name) +(defun ghpr--open-pr/collect-contents (pr diff-content) "Return a string of the title, body, and patch content separated by newlines." (let* ((body (or (alist-get 'body pr) "")) - (number (alist-get 'number pr)) (content-parts (list (ghpr--pr-summary pr)))) (when (not (string-empty-p body)) (push body content-parts)) - (let ((patch-content (ghpr--get-diff-content repo-name number))) - (when patch-content - (push patch-content content-parts))) + (when diff-content + (push diff-content content-parts)) (mapconcat 'identity (reverse content-parts) "\n\n"))) (defun ghpr--open-pr/insert-contents (pr repo-name) "Insert the contents of the pr into the current buffer." (erase-buffer) - (let ((contents (ghpr--open-pr/collect-contents pr repo-name))) + (let* ((number (alist-get 'number pr)) + (diff-content (ghpr--get-diff-content repo-name number)) + (contents (ghpr--open-pr/collect-contents pr diff-content))) + (setq ghpr-review-diff-content diff-content) (insert (ghpr--prefix-lines contents)))) (defun ghpr--open-pr (pr repo-name)