Subject: bug#71883: [PATCH] Fix tab-bar-auto-width with customized tab-bar-tab-face-function

From: Joseph Turner <[email-masked]>
Date: Mon, 01 Jul 2024 13:42:20 -0700

The function tab-bar-auto-width determines which tabs to automatically
resize based on the face applied to each tab's text.  If the face is one
of tab-bar-auto-width-faces, then the tab gets resized.  However, if
either tab-bar-tab-face-function or tab-bar-tab-group-face-function is
set to a function which does not apply one of tab-bar-auto-width-faces,
then the tabs which have a different face are not auto resized.

A real-world example of this issue is in activities.el:

https://github.com/alphapapa/activities.el/issues/76

In the proposed patch, instead of checking each tab's face, we check
that the symbol at the start of each tab keymap matches

(rx bos (or "current-tab" "tab-" "group-"))

Thank you!!

Joseph

>From 4d3f43bfeb0d13a127d161fa9c3bd1737eafe645 Mon Sep 17 00:00:00 2001
From: Joseph Turner <[email-masked]>
Date: Mon, 1 Jul 2024 13:34:06 -0700
Subject: [PATCH] Auto resize based on keymap symbol, not face

* lisp/tab-bar.el (tab-bar-auto-width-faces): Remove defvar.
(tab-bar-auto-width): Match against symbol-name.
---
 lisp/tab-bar.el | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index edec6543a82..f2034616b06 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1216,12 +1216,6 @@ tab-bar-auto-width-min
 It's not recommended to change this value since with larger values, the
 tab bar might wrap to the second line when it shouldn't.")
 
-(defvar tab-bar-auto-width-faces
-  '( tab-bar-tab tab-bar-tab-inactive
-     tab-bar-tab-ungrouped
-     tab-bar-tab-group-inactive)
-  "Resize tabs only with these faces.")
-
 (defvar tab-bar--auto-width-hash nil
   "Memoization table for `tab-bar-auto-width'.")
 
@@ -1250,8 +1244,8 @@ tab-bar-auto-width
         (width 0))    ;; resize tab names to this width
     (dolist (item items)
       (when (and (eq (nth 1 item) 'menu-item) (stringp (nth 2 item)))
-        (if (memq (get-text-property 0 'face (nth 2 item))
-                  tab-bar-auto-width-faces)
+        (if (string-match-p "\\`\\(?:current-tab\\|\\(?:group\\|tab\\)-\\)"
+                            (symbol-name (nth 0 item)))
             (push item tabs)
           (unless (eq (nth 0 item) 'align-right)
             (setq non-tabs (concat non-tabs (nth 2 item)))))))
-- 
2.41.0