Subject: Re: bug#50867: 27.2; window-toggle-side-windows adds an extra window

From: martin rudalics <[email-masked]>
Date: Wed, 29 Sep 2021 11:28:02 +0200

> 1. start a vanila emacs session
 > 2. using scratch buffer, use follow display buffer alist configuration
 >
 > (setq display-buffer-alist
 >            '(("\\*\\(Async Shell Command\\|Shell Command Output\\)\\*"
 >           (display-buffer-reuse-window display-buffer-in-side-window)
 >           (window-width . 0.40)
 >           (side . right)
 >           (slot . 0))))
 >
 > 3. split the window horizontally using `C-x 3`
 > 4. run `M-x async-shell-command ls RET`
 > 5. run `M-x window-toggle-side-windows`
 > 6. run `M-x window-toggle-side-windows`
 >
 > You will see that there is an extra, window added, to the frame.
 >
 >
 >
 > In GNU Emacs 27.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))
 > of 2021-03-28 built on builder10-14.porkrind.org
 > Windowing system distributor 'Apple', version 10.3.2022
 > System Description:  macOS 11.6

Thanks for the report.  I hopefully fixed this now for Emacs 28.  If you
want this to work for Emacs 27, please apply the patch below and either
rebuild Emacs or put the definition of 'window-toggle-side-windows' into
your .emacs.

All the best, martin

diff --git a/lisp/window.el b/lisp/window.el
index b240b16f24..1b02eff17b 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -1212,7 +1216,8 @@ window-toggle-side-windows
       ((setq state (frame-parameter frame 'window-state))
        ;; A window state was saved for FRAME.  Restore it and put the
        ;; current root window into its main window.
-      (let ((main-state (window-state-get (frame-root-window frame))))
+      (let ((window-combination-resize t)
+            (main-state (window-state-get (frame-root-window frame))))
          (window-state-put state (frame-root-window frame) t)
          (window-state-put main-state (window-main-window frame)))
        (window--sides-reverse-frame frame))