From f45a776fe3c9160c49fdf21a96d37d2ed780836c Mon Sep 17 00:00:00 2001 From: shipmints Date: Thu, 30 Jan 2025 12:57:00 -0500 Subject: [PATCH] Add new variable tab-bar-format-tab-help-text-function * lisp/tab-bar.el (tab-bar--format-tab): Add new variable 'tab-bar-format-tab-help-text-function' and a default function 'tab-bar-format-tab-help-text-default'. 'tab-bar--format-tab' respects this new variable when producing a tab's help text, normally shown in the echo area or via tooltips (bug#75950). --- etc/NEWS | 7 +++++++ lisp/tab-bar.el | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 7f6084490d8..2b1951c7b0b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -256,6 +256,13 @@ This is useful to avoid key binding conflicts, such as when folding in outline mode using TAB keys, or when a user wants to define her own tab-bar keys without first having to remove the defaults. +--- +*** New variable 'tab-bar-format-tab-help-text-function'. +This variable may be overridden with a user-provided function to +customize help text for tabs displayed on the tab-bar. Help text is +normally shown in the echo area or via tooltips. See the variable's +docstring for arguments passed to a help-text function. + ** Project --- diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 85a1bb59dc8..4b676ca89da 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -992,6 +992,17 @@ You can hide these buttons by customizing `tab-bar-format' and removing menu-item ,tab-bar-forward-button tab-bar-history-forward :help "Click to go forward in tab history")))) +(defun tab-bar-format-tab-help-text-default (tab _i) + (alist-get 'name tab)) + +(defvar tab-bar-format-tab-help-text-function #'tab-bar-format-tab-help-text-default + "Function to produce help text for tabs displayed in the tab bar. +This function should accept two arguments: the tab, and the one-based +tab's number. + +The function should produce a string, which may be propertized. By +default, use function `tab-bar-format-tab-help-text-default.") + (defun tab-bar--format-tab (tab i) "Format TAB using its index I and return the result as a keymap." (append @@ -1002,13 +1013,13 @@ You can hide these buttons by customizing `tab-bar-format' and removing menu-item ,(funcall tab-bar-tab-name-format-function tab i) ignore - :help ,(alist-get 'name tab)))) + :help ,(funcall tab-bar-format-tab-help-text-function tab i)))) (t `((,(intern (format "tab-%i" i)) menu-item ,(funcall tab-bar-tab-name-format-function tab i) ,(alist-get 'binding tab) - :help ,(alist-get 'name tab))))) + :help ,(funcall tab-bar-format-tab-help-text-function tab i))))) (when (alist-get 'close-binding tab) `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i)))