Subject: bug#46299: 28.0.50; Value of tab-bar-show not respected in new frames.

From: Bastian Beranek <[email-masked]>
Date: Sat, 6 Feb 2021 13:16:54 +0100

Hello Juri,

I added code to make the frame setting of tab-bar-lines as well as the
default-frame-alist value dependent on tab-bar-show to the
tab-bar-mode function.
I think with this the part to which sets frame parameters in
tab-bar-show :set is not needed because (tab-bar-mode 1) is called
anyway, which already does everything.

What do you think about the attached patch?

Cheers
Bastian

On Fri, Feb 5, 2021 at 3:11 PM Bastian Beranek
<[email-masked]> wrote:
>
> Hello Juri,
>
> I now installed your patch and I don't think it is complete yet.
>
> 1) Is the :set function actually used the next time emacs starts after
> customizations have been written to .emacs and variables are
> initialized to customized values using (custom-set-variables ...)? I
> don't think it is, right?
>
> 2) Switching tab-bar-mode on and off seems to overwrite the
> tab-bar-lines information in default-frame-alist:
>
>     ;; If the user has given `default-frame-alist' a `tab-bar-lines'
>     ;; parameter, replace it.
>     (if (assq 'tab-bar-lines default-frame-alist)
>         (setq default-frame-alist
>               (cons (cons 'tab-bar-lines val)
>                     (assq-delete-all 'tab-bar-lines
>                                      default-frame-alist)))))
>
> This code should depend on the value of tab-bar-show, right?
>
> Cheers
> Bastian
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 6720d82b47..1741173bbe 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -139,16 +139,21 @@ Possible modifier keys are `control', `meta', `shift', `hyper', `super' and
   :global t
   ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
   :variable tab-bar-mode
-  (let ((val (if tab-bar-mode 1 0)))
+
+  ;; Set frame parameters.
+  (let ((defaultval (if (and tab-bar-mode tab-bar-show) 1 0)))
     (dolist (frame (frame-list))
-      (set-frame-parameter frame 'tab-bar-lines val))
-    ;; If the user has given `default-frame-alist' a `tab-bar-lines'
-    ;; parameter, replace it.
-    (if (assq 'tab-bar-lines default-frame-alist)
-        (setq default-frame-alist
-              (cons (cons 'tab-bar-lines val)
-                    (assq-delete-all 'tab-bar-lines
-                                     default-frame-alist)))))
+      (let ((frameval (if (natnump tab-bar-show)
+                          (if (and defaultval
+                                   (> (length (funcall tab-bar-tabs-function frame)) tab-bar-show))
+                              1 0)
+                        defaultval)))
+        (set-frame-parameter frame 'tab-bar-lines frameval)))
+    (let ((newframeval (if (and defaultval (eq tab-bar-show t)) 1 0)))
+      (setq default-frame-alist
+            (cons (cons 'tab-bar-lines newframeval)
+                  (assq-delete-all 'tab-bar-lines default-frame-alist)))))
+
   (when tab-bar-mode
     (tab-bar--load-buttons))
   (if tab-bar-mode
@@ -251,16 +256,7 @@ you can use the command `toggle-frame-tab-bar'."
   :set (lambda (sym val)
          (set-default sym val)
          ;; Preload button images
-         (tab-bar-mode 1)
-         ;; Then handle each frame individually
-         (dolist (frame (frame-list))
-           (set-frame-parameter
-            frame 'tab-bar-lines
-            (if (or (eq val t)
-                    (and (natnump val)
-                         (> (length (funcall tab-bar-tabs-function frame))
-                            val)))
-                1 0))))
+         (tab-bar-mode 1))
   :group 'tab-bar
   :version "27.1")