emacs-diffs
[Top][All Lists]
Advanced

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

master 7469214: * lisp/tab-bar.el (tab-bar-tab-name-format-function): Ne


From: Juri Linkov
Subject: master 7469214: * lisp/tab-bar.el (tab-bar-tab-name-format-function): New defcustom.
Date: Tue, 5 Jan 2021 13:55:57 -0500 (EST)

branch: master
commit 7469214d94981d4dbc1ca83a427000fd2b257b47
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/tab-bar.el (tab-bar-tab-name-format-function): New defcustom.
    
    (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        |  9 +++++++++
 lisp/tab-bar.el | 40 ++++++++++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d1cc422..48fb4b8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -396,11 +396,20 @@ 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
 the mouse pointer is in the tab line by scrolling left or right.
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index b44fcfa..5a95e59 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -436,6 +436,30 @@ Return its existing value or a new value."
     tabs))
 
 
+(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 ()



reply via email to

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