Subject: Re: bug#53662: 29.0.50; Cannot use tab-new from side window

From: Juri Linkov <[email-masked]>
Date: Wed, 02 Feb 2022 21:37:09 +0200

> Two caveats:
>
> +      (dolist (parameter (window-parameters))
> +        (set-window-parameter nil (car parameter) nil))
>
> Maybe you should remove the 'window-side' and the 'window-atom'
> parameters only - users can assign arbitrary parameters to windows.

If other window parameters are harmless, then only these two could be
removed.

> +        (unless (eq tab-bar-new-tab-choice 'window)
> +          ;; Create a new window to get rid of old window parameters
> +          ;; (e.g. prev/next buffers) of old window.
> +          (split-window) (delete-window)))
>
> Note that this will lose other settings as well like the window's
> dedicated status.  If this is the intended behavior, you should at least
> tell so in the doc-string.

If you mean the case when tab-bar-new-tab-choice is 'window',
then it will lose only 'window-atom' and 'window-side', because
the value 'window' is intended to keep a single window on the tab.

In other cases at this point, all windows were already saved to
window-configuration, so this window is disposable and can be modified
before immediately deleting it.  After saving windows to
window-configuration, the task here is just to create a new window.

So now a new patch with the updated doc-string:

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 06ad8f60af..e611711092 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -474,6 +474,9 @@ tab-bar-new-tab-choice
 If t, start a new tab with the current buffer, i.e. the buffer
 that was current before calling the command that adds a new tab
 (this is the same what `make-frame' does by default).
+If the value is the symbol `window', then keep the selected
+window as a single window on the new tab, and keep all its
+window parameters except 'window-atom' and 'window-side'.
 If the value is a string, use it as a buffer name to switch to
 if such buffer exists, or switch to a buffer visiting the file or
 directory that the string specifies.  If the value is a function,
@@ -481,6 +484,7 @@ tab-bar-new-tab-choice
 If nil, duplicate the contents of the tab that was active
 before calling the command that adds a new tab."
   :type '(choice (const     :tag "Current buffer" t)
+                 (const     :tag "Current window" window)
                  (string    :tag "Buffer" "*scratch*")
                  (directory :tag "Directory" :value "~/")
                  (file      :tag "File" :value "~/.emacs")
@@ -1361,12 +1365,17 @@ tab-bar-new-tab-to
       ;; Handle the case when it's called in the active minibuffer.
       (when (minibuffer-selected-window)
         (select-window (minibuffer-selected-window)))
+      ;; Remove window parameters that can cause problems
+      ;; with `delete-other-windows' and `split-window'.
+      (set-window-parameter nil 'window-atom nil)
+      (set-window-parameter nil 'window-side nil)
       (let ((ignore-window-parameters t))
-        (delete-other-windows))
-      (unless (eq tab-bar-new-tab-choice 'window)
-        ;; Create a new window to get rid of old window parameters
-        ;; (e.g. prev/next buffers) of old window.
-        (split-window) (delete-window))
+        (delete-other-windows)
+        (unless (eq tab-bar-new-tab-choice 'window)
+          ;; Create a new window to get rid of old window parameters
+          ;; (e.g. prev/next buffers) of old window.
+          (split-window) (delete-window)))
+
       (let ((buffer
              (if (functionp tab-bar-new-tab-choice)
                  (funcall tab-bar-new-tab-choice)