diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 6720d82b47..03ddd75881 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -134,21 +134,30 @@ Possible modifier keys are `control', `meta', `shift', `hyper', `super' and :ascent center)) tab-bar-close-button))) +(defun tab-bar--update-tab-bar-lines () + ;; Set frame parameters. + (let ((defaultval (if (and tab-bar-mode tab-bar-show) 1 0))) + (dolist (frame (frame-list)) + (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)))))) + (define-minor-mode tab-bar-mode "Toggle the tab bar in all graphical frames (Tab Bar mode)." :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))) - (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))))) + + ;; Recalculate tab-bar-lines for all frames + (tab-bar--update-tab-bar-lines) + (when tab-bar-mode (tab-bar--load-buttons)) (if tab-bar-mode @@ -252,15 +261,7 @@ you can use the command `toggle-frame-tab-bar'." (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--update-tab-bar-lines)) :group 'tab-bar :version "27.1") @@ -852,16 +853,11 @@ After the tab is created, the hooks in (run-hook-with-args 'tab-bar-tab-post-open-functions (nth to-index tabs))) - (cond - ((eq tab-bar-show t) - (tab-bar-mode 1)) - ((and (natnump tab-bar-show) - (> (length (funcall tab-bar-tabs-function)) tab-bar-show) - (zerop (frame-parameter nil 'tab-bar-lines))) - (progn - (tab-bar--load-buttons) - (tab-bar--define-keys) - (set-frame-parameter nil 'tab-bar-lines 1)))) + ;; Recalculate tab-bar-lines and update frames + (tab-bar--update-tab-bar-lines) + (when tab-bar-mode + (tab-bar--load-buttons) + (tab-bar--define-keys)) (force-mode-line-update) (unless tab-bar-mode @@ -996,11 +992,8 @@ for the last tab on a frame is determined by tab-bar-closed-tabs) (set-frame-parameter nil 'tabs (delq close-tab tabs))) - (when (and (not (zerop (frame-parameter nil 'tab-bar-lines))) - (natnump tab-bar-show) - (<= (length (funcall tab-bar-tabs-function)) - tab-bar-show)) - (set-frame-parameter nil 'tab-bar-lines 0)) + ;; Recalculate tab-bar-lines and update frames + (tab-bar--update-tab-bar-lines) (force-mode-line-update) (unless tab-bar-mode @@ -1036,11 +1029,8 @@ for the last tab on a frame is determined by (run-hook-with-args 'tab-bar-tab-pre-close-functions (nth index tabs) nil))) (set-frame-parameter nil 'tabs (list (nth current-index tabs))) - (when (and (not (zerop (frame-parameter nil 'tab-bar-lines))) - (natnump tab-bar-show) - (<= (length (funcall tab-bar-tabs-function)) - tab-bar-show)) - (set-frame-parameter nil 'tab-bar-lines 0)) + ;; Recalculate tab-bar-lines and update frames + (tab-bar--update-tab-bar-lines) (force-mode-line-update) (unless tab-bar-mode