]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tab-line.el: Allow user-defined cache-key function (bug#57848)
authorJuri Linkov <juri@linkov.net>
Sun, 30 Oct 2022 17:38:41 +0000 (19:38 +0200)
committerJuri Linkov <juri@linkov.net>
Sun, 30 Oct 2022 17:38:41 +0000 (19:38 +0200)
(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

index 3aa03e543a8b416318be3fb22672a6d2747d68a2..e5e5b7b2ec75d49b6de46fb22cf94458bc129cae 100644 (file)
@@ -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.