Replies: 1 comment 1 reply
-
This is actually something I've been missing too. Using default However, I have been missing a couple things:
@tarsius do you think this is something you want to include in future release? Would you be interested in reviewing a PR? I am happy to cut a one, but will appreciate your input so that it won't step over your future plans. Using @jdormit solution as a starting point I came up with this: (defvar-local pk/forge--pullreq-diff-buffer-winconf nil
"A cons in form (BUFFER . WINCONF).
The BUFFER is diff buffer created for a pull-request, while
WINCONF is a windows configuration prior to displaying
new-pullreq buffer.")
(defun pk/forge--diff-for-pullreq ()
"Show diff for the current pull-request."
(interactive)
(when-let* ((magit-commit-show-diff)
(target forge--buffer-base-branch)
(source forge--buffer-head-branch)
(pullreq-buffer (current-buffer)))
(let ((diff-buffer (magit-diff-range (format "%s..%s" source target))))
(with-current-buffer pullreq-buffer
(setq pk/forge--pullreq-diff-buffer-winconf
(cons diff-buffer
(cdr pk/forge--pullreq-diff-buffer-winconf)))))))
(defun pk/forge--store-winconf (orig-fun &rest args)
; checkdoc-params: (orig-fun args)
"Store windows configuration."
(let ((winconf (current-window-configuration))
(buffer (apply orig-fun args)))
(with-current-buffer buffer
(setq pk/forge--pullreq-diff-buffer-winconf (cons nil winconf)))
buffer))
(defun pk/forge--kill-diff-buffer-restrore-winconf (orig-fun &rest args)
; checkdoc-params: (orig-fun args)
"Kill a buffer set in `pk/forge--pullreq-diff-buffer'."
(pcase-let ((`(,diff-buffer . ,winconf)
pk/forge--pullreq-diff-buffer-winconf))
(apply orig-fun args)
(when diff-buffer
(with-current-buffer diff-buffer
(magit-mode-bury-buffer 'kill))
(when winconf
(set-window-configuration winconf)))))
(add-hook 'forge-create-pullreq-hook #'pk/forge--diff-for-pr)
(advice-add 'pk/forge--prepare-post-buffer
:around #'pk/forge--store-winconf)
(advice-add 'forge-post-cancel
:around #'pk/forge--kill-diff-buffer-restrore-winconf)
(advice-add 'forge-post-submit
:around #'pk/forge--kill-diff-buffer-restrore-winconf) It's not that pretty, as advices are involved and internal
|
Beta Was this translation helpful? Give feedback.
-
One of my favorite features of Magit is that a diff buffer pops up when you go to write a commit message. It would be awesome if Forge had an option to enable similar behavior when writing a pull request. I have a function in my personal config to do this:
This works fine for me, but I'm wondering if there is enough demand for this to make it worth including in Forge itself? Or does this functionality already exist and I just missed it?
Beta Was this translation helpful? Give feedback.
All reactions