Subject: tab-bar-new-tab-to now handles cases with multiple side-windows
From: Benson Chu <[email-masked]>
To: [email-masked]
Date: Fri, 24 Mar 2023 16:07:22 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I've noticed that when I call #'tab-bar-new-tab while I'm in a
side-window that has siblings, I get an error from
#'window--sides-check, which happens when #'tab-bar-new-tab calls
#'delete-other-windows. Here's an example of my problem:

(progn
  (display-buffer-in-side-window (get-buffer-create "*hello*")
                                 '((side . right)
                                   (slot . 1)))
  (select-window
   (display-buffer-in-side-window (get-buffer-create "*world*")
                                  '((side . right)
                                    (slot . 2))))
  (tab-bar-new-tab))

The attached patch fixes this issue. Could it be applied to the emacs-29
branch?

Thanks!
From cc8974b45d5726a0f6a8d9ab6566411c118a0769 Mon Sep 17 00:00:00 2001
From: Benson Chu <[email-masked]>
Date: Fri, 24 Mar 2023 15:38:03 -0500
Subject: [PATCH] tab-bar-new-tab-to now handles cases with multiple
 side-windows

Previously, calling tab-bar-new-tab-to only removes the 'window-side
property on the currently selected window, and then a call to
delete-other-windows was made to ensure that the selected window was
the only window.

However, if there are other side-windows (with the same side) present,
the call to delete-other-windows will fail on the
window--sides-check. This is because according to the check, all
windows on the same side should have the same 'window-side, and
because we only removed the 'window-side parameters on one of the
windows, there will be inconsistencies with that window and its parent
and siblings. Because of this, the call to delete-other-windows to
fail.

This patch makes sure that all windows on a given side will have
'window-side set to nil, so that the call to delete-other-windows will
not fail.

* lisp/tab-bar.el: remove 'window-side from selected window, window's
parent, and all window's siblings.
---
 lisp/tab-bar.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index dce6fa735fc..f05abffbcdb 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1556,7 +1556,13 @@ tab-bar-new-tab-to
       ;; with `delete-other-windows' and `split-window'.
       (unless (eq tab-bar-new-tab-choice 'clone)
         (set-window-parameter nil 'window-atom nil)
-        (set-window-parameter nil 'window-side nil))
+        (let ((side (window-parameter nil 'window-side)))
+          (when side
+            (walk-window-tree
+             (lambda (window)
+               (when (eq side (window-parameter window 'window-side))
+                 (set-window-parameter window 'window-side nil)))
+             nil t))))
       (let ((ignore-window-parameters t))
         (if (eq tab-bar-new-tab-choice 'clone)
             ;; Create new unique windows with the same layout
-- 
2.40.0