emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ed761a793f 1/2: Add abnormal hook to determine which tabs to aut


From: Juri Linkov
Subject: master 9ed761a793f 1/2: Add abnormal hook to determine which tabs to auto-widen
Date: Mon, 19 Aug 2024 12:58:11 -0400 (EDT)

branch: master
commit 9ed761a793f0f11ffea1d2cfa9b7ff38a58d3fe1
Author: Joseph Turner <joseph@breatheoutbreathe.in>
Commit: Juri Linkov <juri@linkov.net>

    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.
---
 etc/NEWS        |  6 ++++++
 lisp/tab-bar.el | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index de1d92764f0..2ddbab29528 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -74,6 +74,12 @@ that the actual killing or burying of the buffer is done by 
the caller.
 With this option set, 'quit-restore-window' will delete its window more
 aggressively rather than switching to some other buffer in it.
 
+** Tab Bars and Tab Lines
+
+---
+*** New abnormal hook 'tab-bar-auto-width-functions'.
+This hook allows you to control which tab-bar tabs are auto-resized.
+
 
 * Editing Changes in Emacs 31.1
 
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 8164ec51498..6133915b591 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1244,6 +1244,18 @@ tab bar might wrap to the second line when it 
shouldn't.")
      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'.")
 
@@ -1272,8 +1284,7 @@ be scaled for display on the current frame."
         (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 (run-hook-with-args-until-success 'tab-bar-auto-width-functions 
item)
             (push item tabs)
           (unless (eq (nth 0 item) 'align-right)
             (setq non-tabs (concat non-tabs (nth 2 item)))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]