Make tab-bar-tab-group-format-function backwards-compatible (bug#60073)

* lisp/tab-bar.el (tab-bar--format-tab-group): Add condition-case
with wrong-number-of-arguments for backwards-compatibility.
(tab-bar-tab-group-format-default): Simplify.
This commit is contained in:
Juri Linkov 2022-12-15 20:03:24 +02:00
parent b211a63455
commit 6e2923d80f

View file

@ -844,9 +844,9 @@ Function gets one argument: a tab."
(defcustom tab-bar-tab-group-format-function #'tab-bar-tab-group-format-default
"Function to format a tab group name.
Function gets three arguments, a tab with a group name, its
number and an optional t when the tab is current, and should
return the formatted tab group name to display in the tab bar."
Function gets three arguments, a tab with a group name, its number, and
an optional value that is non-nil when the tab is from the current group.
It should return the formatted tab group name to display in the tab bar."
:type 'function
:initialize 'custom-initialize-default
:set (lambda (sym val)
@ -856,12 +856,10 @@ return the formatted tab group name to display in the tab bar."
:version "28.1")
(defun tab-bar-tab-group-format-default (tab i &optional current-p)
(let ((name (concat (if tab-bar-tab-hints (format "%d " i) "")
(funcall tab-bar-tab-group-function tab)))
(face (if current-p
'tab-bar-tab-group-current
'tab-bar-tab-group-inactive)))
(propertize name 'face face)))
(propertize
(concat (if (and tab-bar-tab-hints (not current-p)) (format "%d " i) "")
(funcall tab-bar-tab-group-function tab))
'face (if current-p 'tab-bar-tab-group-current 'tab-bar-tab-group-inactive)))
(defcustom tab-bar-tab-group-face-function #'tab-bar-tab-group-face-default
"Function to define a tab group face.
@ -884,7 +882,16 @@ when the tab is current. Return the result as a keymap."
`((,(intern (format "sep-%i" i)) menu-item ,(tab-bar-separator) ignore))
`((,(intern (format "group-%i" i))
menu-item
,(funcall tab-bar-tab-group-format-function tab i current-p)
,(if current-p
(condition-case nil
(funcall tab-bar-tab-group-format-function tab i current-p)
;; We used to define tab-bar-tab-group-format-function as
;; taking two arguments but after adding the third argument
;; we need to provide backwards-compatibility.
(wrong-number-of-arguments
(propertize (funcall tab-bar-tab-group-function tab)
'face 'tab-bar-tab-group-current)))
(funcall tab-bar-tab-group-format-function tab i))
,(if current-p 'ignore
(or
(alist-get 'binding tab)