Subject: Re: bug#78897: Ediff 2.81.6; Window restoration with ediff-before-setup-hook doesn't work for ediff-regions-linewise

From: Eli Zaretskii <[email-masked]>
Date: Sat, 05 Jul 2025 11:09:03 +0300

> Cc: [email-masked]
> Date: Wed, 25 Jun 2025 16:40:51 -0400
> From:  Aaron Zeng via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> ediff-before-setup-hook's docstring suggests using it to save and
> restore the window configuration prior to invoking an Ediff command.
> Users at my site have an equivalent to the following hooks:
> 
> (defvar my-saved-window-configuration nil)
> (add-hook 'ediff-before-setup-hook
>           (lambda ()
>             (setq my-saved-window-configuration (current-window-configuration))))
> (add-hook 'ediff-quit-hook
>           (lambda ()
>             (set-window-configuration my-saved-window-configuration)
>             (setq my-saved-window-configuration nil)))
> 
> This works fine for most Ediff commands but does not work correctly
> with ediff-regions-linewise and ediff-regions-wordwise.  You can
> reproduce the behavior from emacs -Q:
> 
> 1. emacs -Q
> 2. Evaluate the above snippet
> 3. M-x ediff-regions-linewise (select an arbitrary pair of buffers and
>    regions like selecting *scratch* twice)
> 4. Press q
> 
> After quitting, the original window configuration is not restored.  In
> particular, the window is split vertically with a short window below
> the selected taller one.
> 
> I believe this is because those commands use
> ediff-clone-buffer-for-region-comparison to prompt for regions as diff
> input, and that involves adjusting the window configuration a few
> times.  The following patch seems to fix the behavior (edited to
> remove the indentation diff for brevity):

Thanks, I've now installed this on the master branch, and I'm
therefore closing this bug.