Skip to content

Commit

Permalink
Merge pull request #236 from ema2159/perf/db
Browse files Browse the repository at this point in the history
perf: Update buffer groups only when needed
  • Loading branch information
jcs090218 authored Jun 20, 2024
2 parents e7d322a + 0f323b6 commit 45bf522
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion centaur-tabs-elements.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@

(defface centaur-tabs-dim-buffer-face
'((t (:foreground "gray40")))
"Face for the buffer when centaur-tabs-ace-jump is invoked.")
"Face for the buffer when centaur-tabs-ace-jump is invoked."
:group 'centaur-tabs)

;;
;;; Tabs' display line
Expand Down
18 changes: 14 additions & 4 deletions centaur-tabs-functions.el
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,22 @@ current cached copy."
(centaur-tabs-set-template centaur-tabs-tabsets-tabset nil)
centaur-tabs-tabsets-tabset)

(defun centaur-tabs-on-window-buffer-change (&rest _)
"Function to be run after window buffer is changed."
(centaur-tabs-buffer-update-groups))

;; Functions for modification hooks and advices
(defun centaur-tabs-on-saving-buffer ()
"Function to be run after the buffer is saved."
(centaur-tabs-set-template centaur-tabs-current-tabset nil)
(centaur-tabs-display-update))

(defun centaur-tabs-on-modifying-buffer ()
"Function to be run after the buffer is first changed."
(set-buffer-modified-p (buffer-modified-p))
(centaur-tabs-set-template centaur-tabs-current-tabset nil)
(centaur-tabs-display-update))

(defun centaur-tabs-after-modifying-buffer (&rest _)
"Function to be run after the buffer is changed.
BEGIN, END and LENGTH are just standard arguments for after-changes-function
Expand Down Expand Up @@ -1001,8 +1007,7 @@ Depend on the setting of the option `centaur-tabs-cycle-scope'."

(defun centaur-tabs-filter-out (condp lst)
"Filter list LST with using CONDP as the filtering condition."
(delq nil
(mapcar (lambda (x) (if (funcall condp x) nil x)) lst)))
(delq nil (mapcar (lambda (x) (if (funcall condp x) nil x)) lst)))

(defun centaur-tabs-buffer-list ()
"Return the list of buffers to show in tabs.
Expand Down Expand Up @@ -1079,7 +1084,12 @@ Return the the first group where the current buffer is."
(unless (centaur-tabs-tabs tabset)
tabset))))
;; The new cache becomes the current one.
(setq centaur-tabs--buffers bl)))
(setq centaur-tabs--buffers bl))))

(defun centaur-tabs-buffer-update-groups-cache ()
"Don't call function `centaur-tabs-buffer-update-groups' too often."
(unless centaur-tabs--buffers
(centaur-tabs-buffer-update-groups))
;; Return the first group the current buffer belongs to.
(car (nth 2 (assq (current-buffer) centaur-tabs--buffers))))

Expand All @@ -1092,7 +1102,7 @@ Return the the first group where the current buffer is."

(defun centaur-tabs-buffer-tabs ()
"Return the buffers to display on the tab bar, in a tab set."
(let ((tabset (centaur-tabs-get-tabset (centaur-tabs-buffer-update-groups))))
(let ((tabset (centaur-tabs-get-tabset (centaur-tabs-buffer-update-groups-cache))))
(centaur-tabs-select-tab-value (current-buffer) tabset)
(when centaur-tabs--buffer-show-groups
(setq tabset (centaur-tabs-get-tabsets-tabset))
Expand Down
1 change: 1 addition & 0 deletions centaur-tabs.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Run as `centaur-tabs-init-hook'."
(set-face-attribute 'centaur-tabs-unselected-modified nil
:overline nil
:underline nil))
(add-hook 'window-buffer-change-functions #'centaur-tabs-on-window-buffer-change)
(add-hook 'after-save-hook #'centaur-tabs-on-saving-buffer)
(add-hook 'first-change-hook #'centaur-tabs-on-modifying-buffer)
(add-hook 'kill-buffer-hook #'centaur-tabs-buffer-track-killed)
Expand Down

0 comments on commit 45bf522

Please sign in to comment.