From c044ad3ab6a37c2cd6cec434926e3c21eb84bec9 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 5 Jul 2025 11:07:29 +0300 Subject: [PATCH] Fix 'ediff-before-setup-hook' * lisp/vc/ediff-util.el (ediff-clone-buffer-for-region-comparison): Wrap body in 'save-window-excursion', to make sure original window configuration is restored after quitting 'ediff-regions-linewise'. Suggested by Aaron Zeng . (Bug#78897) (cherry picked from commit 34dad30e49e4d7768d74f2d32544845a893b0796) --- lisp/vc/ediff-util.el | 81 ++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/lisp/vc/ediff-util.el b/lisp/vc/ediff-util.el index d80b79ee1c7..61e90e52bb4 100644 --- a/lisp/vc/ediff-util.el +++ b/lisp/vc/ediff-util.el @@ -3220,46 +3220,47 @@ Without an argument, it saves customized diff argument, if available ;; idea suggested by Hannu Koivisto (defun ediff-clone-buffer-for-region-comparison (buff region-name) - (let ((cloned-buff (ediff-make-cloned-buffer buff region-name)) - (pop-up-windows t) - wind - other-wind - msg-buf) - (ediff-with-current-buffer cloned-buff - (setq ediff-temp-indirect-buffer t)) - (pop-to-buffer cloned-buff) - (setq wind (ediff-get-visible-buffer-window cloned-buff)) - (when (window-live-p wind) - (select-window wind) - (delete-other-windows)) - (or (mark) (push-mark)) - (setq mark-active 'ediff-util) - (setq-local transient-mark-mode t) - (split-window-vertically) - (ediff-select-lowest-window) - (setq other-wind (selected-window)) - (with-temp-buffer - (erase-buffer) - (insert - (format "\n ******* Mark a region in buffer %s (or confirm the existing one) *******\n" - (buffer-name cloned-buff))) - (insert - (ediff-with-current-buffer buff - (format "\n\t When done, type %s Use %s to abort\n " - (ediff-format-bindings-of 'exit-recursive-edit) - (ediff-format-bindings-of 'abort-recursive-edit)))) - (goto-char (point-min)) - (setq msg-buf (current-buffer)) - (set-window-buffer other-wind msg-buf) - (shrink-window-if-larger-than-buffer) - (if (window-live-p wind) - (select-window wind)) - (condition-case nil - (recursive-edit) - (quit - (ediff-kill-buffer-carefully cloned-buff))) - ) - cloned-buff)) + (save-window-excursion + (let ((cloned-buff (ediff-make-cloned-buffer buff region-name)) + (pop-up-windows t) + wind + other-wind + msg-buf) + (ediff-with-current-buffer cloned-buff + (setq ediff-temp-indirect-buffer t)) + (pop-to-buffer cloned-buff) + (setq wind (ediff-get-visible-buffer-window cloned-buff)) + (when (window-live-p wind) + (select-window wind) + (delete-other-windows)) + (or (mark) (push-mark)) + (setq mark-active 'ediff-util) + (setq-local transient-mark-mode t) + (split-window-vertically) + (ediff-select-lowest-window) + (setq other-wind (selected-window)) + (with-temp-buffer + (erase-buffer) + (insert + (format "\n ******* Mark a region in buffer %s (or confirm the existing one) *******\n" + (buffer-name cloned-buff))) + (insert + (ediff-with-current-buffer buff + (format "\n\t When done, type %s Use %s to abort\n " + (ediff-format-bindings-of 'exit-recursive-edit) + (ediff-format-bindings-of 'abort-recursive-edit)))) + (goto-char (point-min)) + (setq msg-buf (current-buffer)) + (set-window-buffer other-wind msg-buf) + (shrink-window-if-larger-than-buffer) + (if (window-live-p wind) + (select-window wind)) + (condition-case nil + (recursive-edit) + (quit + (ediff-kill-buffer-carefully cloned-buff))) + ) + cloned-buff))) (defun ediff-clone-buffer-for-window-comparison (buff wind region-name) -- 2.39.5