From ca66acf2a4ded69e07a796d3feb1906072c20e6c Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Mon, 15 Jul 2024 21:55:35 -0700 Subject: [PATCH 2/4] Add abnormal hook to determine which tabs to auto-widen * lisp/tab-bar.el (tab-bar-auto-width-predicate-default): Default value for tab-bar-auto-width-functions. (tab-bar-auto-width-functions): New abnormal hook. (tab-bar-auto-width): Run new abnormal hook until success instead of comparing text properties on Emacs 31 or later. --- lisp/tab-bar.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 66fb9490ce8..86259f36df5 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1222,6 +1222,18 @@ tab-bar-auto-width-faces tab-bar-tab-group-inactive) "Resize tabs only with these faces.") +(defun tab-bar-auto-width-predicate-default (item) + "Accepts tab ITEM and returns non-nil for tabs and tab groups." + (string-match-p + ;; (rx bos (or "current-tab" "current-group" "tab-" "group-")) + "\\`\\(?:current-\\(?:group\\|tab\\)\\|\\(?:group\\|tab\\)-\\)" + (symbol-name (nth 0 item)))) + +(defvar tab-bar-auto-width-functions '(tab-bar-auto-width-predicate-default) + "List of functions for `tab-bar-auto-width' to call with a tab ITEM. +If any of these functions returns non-nil for a given tab ITEM, that +tab's width will be auto-sized.") + (defvar tab-bar--auto-width-hash nil "Memoization table for `tab-bar-auto-width'.") @@ -1250,8 +1262,10 @@ 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 (if (version<= "31" emacs-version) + (run-hook-with-args-until-success 'tab-bar-auto-width-functions item) + (memq (get-text-property 0 'face (nth 2 item)) + tab-bar-auto-width-faces)) (push item tabs) (unless (eq (nth 0 item) 'align-right) (setq non-tabs (concat non-tabs (nth 2 item))))))) -- 2.41.0