[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 73953b23aa 2/2: * lisp/tab-line.el: Allow user-defined cache-key
From: |
Juri Linkov |
Subject: |
master 73953b23aa 2/2: * lisp/tab-line.el: Allow user-defined cache-key function (bug#57848) |
Date: |
Sun, 30 Oct 2022 13:39:15 -0400 (EDT) |
branch: master
commit 73953b23aad5af80275838cd3b1c88e045e1856e
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
* 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 3aa03e543a..e5e5b7b2ec 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.