From 73953b23aad5af80275838cd3b1c88e045e1856e Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 30 Oct 2022 19:38:41 +0200 Subject: [PATCH] * lisp/tab-line.el: Allow user-defined cache-key function (bug#57848) (tab-line-cache-key-default): New function. (tab-line-cache-key-function): New variable. (tab-line-format): Funcall tab-line-cache-key-function. --- lisp/tab-line.el | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 3aa03e543a8..e5e5b7b2ec7 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -572,19 +572,31 @@ For use in `tab-line-tab-face-functions'." (defvar tab-line-auto-hscroll) +(defun tab-line-cache-key-default (_tabs) + "Return default list of cache keys." + (list + ;; for setting face 'tab-line-tab-current' + (mode-line-window-selected-p) + ;; for `tab-line-tab-face-modified' + (and (memq 'tab-line-tab-face-modified + tab-line-tab-face-functions) + (buffer-file-name) + (buffer-modified-p)))) + +(defvar tab-line-cache-key-function #'tab-line-cache-key-default + "Function that adds more cache keys. +It has one argument with a list of tabs, and returns a list of cache keys. +You can use `add-function' to add more cache keys.") + (defun tab-line-format () "Format for displaying the tab line of the selected window." (let* ((tabs (funcall tab-line-tabs-function)) - (cache-key (list tabs - ;; handle buffer renames - (buffer-name (window-buffer)) - ;; handle tab-line scrolling - (window-parameter nil 'tab-line-hscroll) - ;; for setting face 'tab-line-tab-current' - (mode-line-window-selected-p) - (and (memq 'tab-line-tab-face-modified - tab-line-tab-face-functions) - (buffer-file-name) (buffer-modified-p)))) + (cache-key (append (list tabs + ;; handle buffer renames + (buffer-name (window-buffer)) + ;; handle tab-line scrolling + (window-parameter nil 'tab-line-hscroll)) + (funcall tab-line-cache-key-function tabs))) (cache (window-parameter nil 'tab-line-cache))) ;; Enable auto-hscroll again after it was disabled on manual scrolling. ;; The moment to enable it is when the window-buffer was updated. -- 2.39.2