Skip to content

Commit

Permalink
style: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed May 29, 2024
1 parent 9e5e945 commit fe1f130
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
6 changes: 4 additions & 2 deletions centaur-tabs-elements.el
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,10 @@ The memoization cache is frame-local."
"Return a frame-local hash table that acts as a memoization cache.
The cache is for the powerline.
Create one if the frame doesn't have one yet."
(let ((table (frame-parameter nil 'powerline-cache)))
(if (hash-table-p table) table (centaur-tabs-separator-reset-cache))))
(if-let* ((table (frame-parameter nil 'powerline-cache))
((hash-table-p table)))
table
(centaur-tabs-separator-reset-cache)))

(defun centaur-tabs-separator-reset-cache ()
"Reset and return the frame-local hash table used for a memoization cache."
Expand Down
36 changes: 13 additions & 23 deletions centaur-tabs-functions.el
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,14 @@ That is, remove it from the tab sets store."

(defun centaur-tabs-get-cache (cache key)
"Return the per-frame cached value of KEY in CACHE."
(let
((cached-hash (frame-parameter nil cache)))
(if (hash-table-p cached-hash)
(gethash key cached-hash nil))))
(when-let* ((cached-hash (frame-parameter nil cache))
((hash-table-p cached-hash)))
(gethash key cached-hash nil)))

(defun centaur-tabs-put-cache (cache key value)
"Set the per-frame cached value of KEY in CACHE to VALUE."
(let*
((cached-hash (frame-parameter nil cache))
(hash (if (hash-table-p cached-hash) cached-hash (make-hash-table))))
(let* ((cached-hash (frame-parameter nil cache))
(hash (if (hash-table-p cached-hash) cached-hash (make-hash-table))))
(puthash key value hash)
(set-frame-parameter nil cache hash))
value)
Expand Down Expand Up @@ -616,7 +614,6 @@ remain visible. The active window will the the EVT source."
(centaur-tabs-move-current-tab-to-left)
(centaur-tabs--button-ensure-selected-tab-is-visible evt))


(defun centaur-tabs-move-current-tab-to-right--button (evt)
"Same as centaur-tabs-move-current-tab-to-right, but ensuring the tab will
remain visible. The active window will the the EVT source."
Expand Down Expand Up @@ -779,11 +776,9 @@ Call `centaur-tabs-tab-label-function' to obtain a label for TAB."
That is, a propertized string used as an `centaur-tabs-display-line-format'
template element."
(let* ((face 'centaur-tabs-unselected))
(concat
(propertize
button
'face face
'mouse-face 'highlight))))
(concat (propertize button
'face face
'mouse-face 'highlight))))

(defun centaur-tabs-line-format (tabset)
"Return the `centaur-tabs-display-line-format' value to display TABSET."
Expand Down Expand Up @@ -841,8 +836,7 @@ template element."
(propertize "% "
'face (list :background padcolor)
'pointer 'arrow)
(centaur-tabs-line-format--new-button)))
))
(centaur-tabs-line-format--new-button)))))

(defun centaur-tabs-count (index count)
"Return a centaur-tabs-button-tab with the current tab INDEX and the total
Expand Down Expand Up @@ -920,17 +914,15 @@ instead."
;; to the first/last visible tab.
(unless tab
(setq tabset (centaur-tabs-tabs tabset)
tab (car (if backward (last tabset) tabset))))
)
tab (car (if backward (last tabset) tabset)))))
;; Cycle through tab groups only.
((eq cycle 'groups)
(setq tab (centaur-tabs-tab-next ttabset selected backward))
;; When there is no group after/before the selected one, cycle
;; to the first/last available group.
(unless tab
(setq tabset (centaur-tabs-tabs ttabset)
tab (car (if backward (last tabset) tabset))))
)
tab (car (if backward (last tabset) tabset)))))
(t
;; Cycle through visible tabs then tab groups.
(setq tab (centaur-tabs-tab-next tabset selected backward))
Expand All @@ -945,8 +937,7 @@ instead."
tab (car (if backward (last tabset) tabset))))
;; Select the first/last visible tab of the new group.
(setq tabset (centaur-tabs-tabs (centaur-tabs-tab-tabset tab))
tab (car (if backward (last tabset) tabset))))
))
tab (car (if backward (last tabset) tabset))))))
(centaur-tabs-buffer-select-tab tab))))

;;;###autoload
Expand Down Expand Up @@ -1229,8 +1220,7 @@ buffer changed."
(setq new-group-tabs (centaur-tabs-insert-before base-group-tabs previous-tab current-tab)))))
(set bufset new-group-tabs)
(centaur-tabs-set-template bufset nil)
(centaur-tabs-display-update)
))))
(centaur-tabs-display-update)))))

;; Update the group name of the last accessed tab.
(setq centaur-tabs-last-focused-buffer-group current-group)))))
Expand Down
27 changes: 14 additions & 13 deletions centaur-tabs-interactive.el
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ move forward."
(centaur-tabs-kill-buffer-match-rule
(lambda (buffer) (not (buffer-modified-p buffer))))))


(defun centaur-tabs-kill-match-buffers-in-current-group ()
"Kill all buffers match extension in current group."
(interactive)
Expand All @@ -229,8 +228,7 @@ move forward."
(centaur-tabs-kill-buffer-match-rule
(lambda (buffer)
(let ((filename (buffer-file-name buffer)))
(and filename (string-equal (file-name-extension filename) match-extension))
)))
(and filename (string-equal (file-name-extension filename) match-extension)))))
;; Switch to next group if last file killed.
(when (equal (length extension-names) 1)
(centaur-tabs-forward-group))))
Expand Down Expand Up @@ -426,13 +424,16 @@ Should be buffer local and speed up calculation of buffer groups.")
((string-equal "*" (substring (buffer-name) 0 1)) '("Misc"))
((condition-case _err
(projectile-project-root)
(error nil)) (list (projectile-project-name)))
(error nil))
(list (projectile-project-name)))
((memq major-mode '(emacs-lisp-mode python-mode emacs-lisp-mode c-mode
c++-mode javascript-mode js-mode
js2-mode makefile-mode
lua-mode vala-mode)) '("Coding"))
((memq major-mode '(nxhtml-mode html-mode
mhtml-mode css-mode)) '("HTML"))
lua-mode vala-mode))
'("Coding"))
((memq major-mode '( nxhtml-mode html-mode
mhtml-mode css-mode))
'("HTML"))
((memq major-mode '(org-mode calendar-mode diary-mode)) '("Org"))
((memq major-mode '(dired-mode)) '("Dir"))
(t '("Other"))))
Expand Down Expand Up @@ -628,12 +629,12 @@ The clicked tab, identified by EVENT, is selected."
(defun centaur-tabs--groups-menu ()
"Show a popup menu with the centaur tabs groups."
(interactive)
(let*
((sorted-groups (centaur-tabs--tab-submenu-groups-definition))
(menu (easy-menu-create-menu "Tab groups" (centaur-tabs--tab-submenu-groups-definition)))
(choice (x-popup-menu t menu))
(action (lookup-key menu (apply 'vector choice)))
(action-is-command-p (and (commandp action) (functionp action))))
(let* ((sorted-groups (centaur-tabs--tab-submenu-groups-definition))
(menu (easy-menu-create-menu "Tab groups"
(centaur-tabs--tab-submenu-groups-definition)))
(choice (x-popup-menu t menu))
(action (lookup-key menu (apply 'vector choice)))
(action-is-command-p (and (commandp action) (functionp action))))
(when action-is-command-p
(call-interactively action))
(when (not action-is-command-p)
Expand Down

0 comments on commit fe1f130

Please sign in to comment.