]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tab-bar.el (tab-bar-tab-name-format-function): New defcustom.
authorJuri Linkov <juri@linkov.net>
Tue, 5 Jan 2021 18:55:29 +0000 (20:55 +0200)
committerJuri Linkov <juri@linkov.net>
Tue, 5 Jan 2021 18:55:29 +0000 (20:55 +0200)
(tab-bar-tab-name-format-default): New function as the default value.
(tab-bar-make-keymap-1): Funcall tab-bar-tab-name-format-function.

etc/NEWS
lisp/tab-bar.el

index d1cc422e9f7da0abea82a51ec445b29009cefd44..48fb4b88e15897dc6cdef4b2a096e990bd6227a6 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -396,10 +396,19 @@ of the next command to be displayed in a new tab.
 +++
 *** New command 'C-x t C-r' to open file read-only in other tab.
 
+---
 *** The tab bar is frame-local when 'tab-bar-show' is a number.
 Show/hide the tab bar independently for each frame, according to the
 value of 'tab-bar-show'.
 
+---
+*** New command 'toggle-frame-tab-bar'.
+It can be used to enable/disable the tab bar individually
+on each frame independently from the state of `tab-bar-mode'.
+
+---
+*** New user option 'tab-bar-tab-name-format-function'.
+
 ---
 *** The tabs in the tab line can now be scrolled using horizontal scroll.
 If your mouse or trackpad supports it, you can now scroll tabs when
index b44fcfa3a023993512e7b31b37a8a14de138b4aa..5a95e5975de38df70872c230ec6b90ec324de101 100644 (file)
@@ -436,6 +436,30 @@ Return its existing value or a new value."
     tabs))
 
 \f
+(defcustom tab-bar-tab-name-format-function #'tab-bar-tab-name-format-default
+  "Function to format a tab name.
+Function gets two arguments, the tab and its number, and should return
+the formatted tab name to display in the tab bar."
+  :type 'function
+  :initialize 'custom-initialize-default
+  :set (lambda (sym val)
+         (set-default sym val)
+         (force-mode-line-update))
+  :group 'tab-bar
+  :version "28.1")
+
+(defun tab-bar-tab-name-format-default (tab i)
+  (let ((current-p (eq (car tab) 'current-tab)))
+    (propertize
+     (concat (if tab-bar-tab-hints (format "%d " i) "")
+             (alist-get 'name tab)
+             (or (and tab-bar-close-button-show
+                      (not (eq tab-bar-close-button-show
+                               (if current-p 'non-selected 'selected)))
+                      tab-bar-close-button)
+                 ""))
+     'face (if current-p 'tab-bar-tab 'tab-bar-tab-inactive))))
+
 (defun tab-bar-make-keymap-1 ()
   "Generate an actual keymap from `tab-bar-map', without caching."
   (let* ((separator (or tab-bar-separator (if window-system " " "|")))
@@ -461,25 +485,13 @@ Return its existing value or a new value."
           ((eq (car tab) 'current-tab)
            `((current-tab
               menu-item
-              ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "")
-                                   (alist-get 'name tab)
-                                   (or (and tab-bar-close-button-show
-                                            (not (eq tab-bar-close-button-show
-                                                     'non-selected))
-                                            tab-bar-close-button) ""))
-                           'face 'tab-bar-tab)
+              ,(funcall tab-bar-tab-name-format-function tab i)
               ignore
               :help "Current tab")))
           (t
            `((,(intern (format "tab-%i" i))
               menu-item
-              ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "")
-                                   (alist-get 'name tab)
-                                   (or (and tab-bar-close-button-show
-                                            (not (eq tab-bar-close-button-show
-                                                     'selected))
-                                            tab-bar-close-button) ""))
-                           'face 'tab-bar-tab-inactive)
+              ,(funcall tab-bar-tab-name-format-function tab i)
               ,(or
                 (alist-get 'binding tab)
                 `(lambda ()