branch: elpa/magit
commit 406a3094a883ecf45df277fa920e7ec547b5552a
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit--refresh-buffer-set-positions: Do not mess up window-start
Originally reported in #4156 and fixed with [1: 482c25a320] and
broken again by [2: 10a0994ae8], because I overlooked that the
hunk `magit-section-goto-successor' method does in fact continue
to use `magit-section-goto'.
This effectively reverts the second commit but also adds a new
comment to prevent this from happening again.
1: 2021-05-19 482c25a3204468a4f6c2fe12ff061666b61f5f4d
magit-refresh-buffer: Fix window handling
2: 2025-06-29 10a0994ae8a3d2cd1ef5231c72f226cd71e79e68
magit--refresh-buffer-set-positions: No longer suppress unused hook
---
lisp/magit-mode.el | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index e6b2aadedd8..39c9a6420ce 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1138,7 +1138,10 @@ The arguments are for internal use."
(list ws
(car (magit-section-get-relative-position ws))
(window-start)))))))))
- (get-buffer-window-list buffer nil t)))
+ ;; For hunks we run `magit-section-movement-hook' (once for
+ ;; each window displaying the buffer). The selected window
+ ;; comes first in this list, but we want to process it last.
+ (nreverse (get-buffer-window-list buffer nil t))))
(and-let* ((section (magit-section-at)))
`((nil ,section ,@(magit-section-get-relative-position section))))))
@@ -1160,7 +1163,15 @@ The arguments are for internal use."
ws-section ws-line 0)
(point)))))
(set-window-start window pos t)))))
- (magit-section-goto-successor section line char))))
+ ;; We must make sure this does not call `set-window-start',
+ ;; which the HUNK METHOD does by calling `magit-section-goto'
+ ;; because that runs the `magit-section-goto-successor-hook'
+ ;; and thus `magit-hunk-set-window-start'. The window does
+ ;; not display this buffer, so the window start would be set
+ ;; for the wrong buffer. Originally reported in #4196 and
+ ;; fixed with 482c25a3204468a4f6c2fe12ff061666b61f5f4d.
+ (let ((magit-section-movement-hook nil))
+ (magit-section-goto-successor section line char)))))
(defun magit-revert-buffer (_ignore-auto _noconfirm)
"Wrapper around `magit-refresh-buffer' suitable as `revert-buffer-function'."