/
init-tabbar.el
236 lines (217 loc) · 11.7 KB
/
init-tabbar.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
;; -*- lexical-binding: t; -*-
;; Show persp list when only one persp exists
(defvar +tab-bar-shows-single-empty-persp t)
;; [tab-bar] Tab bar
(use-package tab-bar
:bind
("<f10>" . tab-next)
("s-<right>" . tab-next)
("s-<left>" . tab-previous)
("s-l" . tab-next)
("s-h" . tab-previous)
;; Turn on tab-bar-mode in early-init to speed-up
:hook (window-setup . tab-bar-mode)
:config
(setq tab-bar-separator ""
tab-bar-new-tab-choice "*scratch*"
tab-bar-tab-name-truncated-max 30
tab-bar-auto-width nil
tab-bar-close-button-show nil
tab-bar-tab-hints t
tab-bar-show 1)
(customize-set-variable 'tab-bar-select-tab-modifiers '(super))
;; truncate for [tab name] and add count
(setq tab-bar-tab-name-function
(lambda () (let* ((raw-tab-name (buffer-name (window-buffer (minibuffer-selected-window))))
(count (length (window-list-1 nil 'nomini)))
(truncated-tab-name (if (< (length raw-tab-name)
tab-bar-tab-name-truncated-max)
raw-tab-name
(truncate-string-to-width raw-tab-name
tab-bar-tab-name-truncated-max
nil nil tab-bar-tab-name-ellipsis))))
(if (> count 1)
(concat truncated-tab-name "(" (number-to-string count) ")")
truncated-tab-name))))
;; Add spaces for tab-name
(setq tab-bar-tab-name-format-function
(lambda (tab i)
(let ((face (funcall tab-bar-tab-face-function tab)))
(concat
(propertize " " 'face face)
(propertize (number-to-string i) 'face `(:inherit ,face :weight ultra-bold :underline t))
(propertize (concat " " (alist-get 'name tab) " ") 'face face)))))
;; cache for persp indicator
;; (with-eval-after-load 'persp-mode
;; (defvar +tab-bar-persp-indicator-cache nil)
;; (add-hook! (persp-activated-functions persp-names-cache-changed-functions)
;; (defun +tab-bar-update-persp-indicator (&rest _)
;; (when-let* ((persp-list (persp-names-current-frame-fast-ordered))
;; (len (length persp-list)))
;; (setq +tab-bar-persp-indicator-cache
;; (when (or (> len 1) +tab-bar-shows-single-empty-persp)
;; (let* ((cur-persp-name (safe-persp-name (get-current-persp)))
;; (cur-pos (cl-position cur-persp-name persp-list))
;; (before (seq-subseq persp-list 0 cur-pos))
;; (before-joined (concat (string-join before " ") " "))
;; (after (seq-subseq persp-list (1+ cur-pos)))
;; (after-joined (concat " " (string-join after " ")))
;; (face '(:inherit font-lock-constant-face :inverse-video t))
;; (text (concat (propertize (concat " " (when before before-joined) "") 'face face)
;; (propertize (concat cur-persp-name)
;; 'face (append face '(:weight ultra-bold :underline t :background "white")))
;; (propertize (concat (when after after-joined) " ") 'face face))))
;; `((tab-bar-persp menu-item
;; ,text
;; ignore
;; :help ,(concat "Current persp: " cur-persp-name))))))
;; (force-mode-line-update t)
;; +tab-bar-persp-indicator-cache))))
;;
;; (defun +tab-bar-persp-indicator ()
;; (when (bound-and-true-p persp-mode)
;; (or +tab-bar-persp-indicator-cache
;; (+tab-bar-update-persp-indicator))))
;; cache for telega indicator
;; (with-eval-after-load 'telega
;; (defvar +tab-bar-telega-indicator-cache nil)
;;
;; (add-hook! (telega-connection-state-hook telega-kill-hook telega-online-status-hook)
;; (defun +tab-bar-telega-icon-update (&rest rest)
;; (when (buffer-live-p telega-server--buffer)
;; (let* ((me-user (telega-user-me 'locally))
;; (online-p (and me-user (telega-user-online-p me-user)))
;; ;; reactions
;; (reactions-chats (telega-filter-chats telega--ordered-chats '(and is-known unread-reactions)))
;; (reactions-count (apply '+ (mapcar (telega--tl-prop :unread_reaction_count) reactions-chats)))
;; ;; mentioned
;; (mentioned-chats (telega-filter-chats telega--ordered-chats '(mention)))
;; (mentioned-count (apply '+ (mapcar (telega--tl-prop :unread_mention_count) mentioned-chats)))
;; ;; unread
;; (unmuted-count (or (plist-get telega--unread-chat-count :unread_unmuted_count) 0))
;; (mentioned-unmuted-chats (telega-filter-chats telega--ordered-chats '(and mention unmuted)))
;; (true-unmuted-count (- unmuted-count (length mentioned-unmuted-chats)))
;; (text (propertize (concat " " telega-symbol-telegram " "
;; (when (> true-unmuted-count 0)
;; (concat "●" (number-to-string true-unmuted-count) " "))
;; (when (> mentioned-count 0)
;; (concat "@" (number-to-string mentioned-count) " "))
;; (when (> reactions-count 0)
;; (concat "❤" (number-to-string reactions-count) " ")))
;; 'face `(:inherit font-lock-keyword-face :inverse-video ,online-p)))
;; (first-name (plist-get me-user :first_name))
;; (last-name (plist-get me-user :last_name))
;; (help-echo (concat "Current User: " first-name " " last-name "\n"
;; "Status: " (if online-p "online" "offline"))))
;; (setq +tab-bar-telega-indicator-cache
;; `((tab-bar-persp menu-item
;; ,text
;; ignore
;; :help ,help-echo))))
;; (force-mode-line-update t)
;; +tab-bar-telega-indicator-cache)
;; ))
;;
;; (advice-add 'telega--on-updateUserStatus :after #'+tab-bar-telega-icon-update)
;; (advice-add 'telega--on-updateUnreadChatCount :after #'+tab-bar-telega-icon-update)
;; (advice-add 'telega--on-updateChatUnreadMentionCount :after #'+tab-bar-telega-icon-update)
;; (advice-add 'telega--on-updateChatUnreadReactionCount :after #'+tab-bar-telega-icon-update))
;;
;; (defun +tab-bar-telega-icon ()
;; (when (and (fboundp 'telega-server-live-p)
;; (telega-server-live-p))
;; (or +tab-bar-telega-indicator-cache
;; (+tab-bar-telega-icon-update))))
;;
;; (defun +tab-bar-copilot-icon ()
;; (when (bound-and-true-p copilot-mode)
;; (propertize " α " 'face '(:inherit font-lock-doc-face :inverse-video t))))
;; cache for org-pomodoro
;; (with-eval-after-load 'org-pomodoro
;; (defvar +tab-bar-org-pomodoro-indicator-cache nil)
;;
;; (add-hook! (org-pomodoro-started-hook org-pomodoro-finished-hook org-pomodoro-overtime-hook
;; org-pomodoro-killed-hook org-pomodoro-break-finished-hook
;; org-pomodoro-long-break-finished-hook org-pomodoro-killed-hook)
;; (defun +tab-bar-org-pomodoro-indicator-update (&rest _)
;; (setq +tab-bar-org-pomodoro-indicator-cache
;; (cl-case org-pomodoro-state
;; (:none
;; (propertize " Stop " 'face '(:inherit font-lock-comment-face :inverse-video t)))
;; (:pomodoro
;; (propertize " Pomo " 'face '(:inherit org-pomodoro-mode-line :inverse-video t)))
;; (:overtime
;; (propertize " Over " 'face '(:inherit org-pomodoro-mode-line-overtime :inverse-video t)))
;; (:short-break
;; (propertize " Short break " 'face '(:inherit org-pomodoro-mode-line-break :inverse-video t)))
;; (:long-break
;; (propertize " Long break " 'face '(:inherit org-pomodoro-mode-line-break :inverse-video t))))))
;; ))
;;
;; (defun +tab-bar-org-pomodoro-indicator ()
;; (when (fboundp 'org-pomodoro-active-p)
;; (or +tab-bar-org-pomodoro-indicator-cache
;; (+tab-bar-org-pomodoro-indicator-update))))
;; ime
;; (defvar +tab-bar-rime-active-hint (propertize " ⭘ " 'face '(:inherit rime-indicator-face :inverse-video t)))
;; (defvar +tab-bar-rime-inactive-hint (propertize " ● " 'face '(:inherit rime-indicator-face :inverse-video t)))
;; (defvar +tab-bar-no-ime-hint (propertize " ⭘ " 'face '(:inherit rime-indicator-dim-face :inverse-video t)))
;; (defun +tab-bar-rime-indicator ()
;; (let ((text-help (if (and (equal current-input-method "rime")
;; (bound-and-true-p rime-mode))
;; (if (and (rime--should-enable-p)
;; (not (rime--should-inline-ascii-p)))
;; (cons +tab-bar-rime-active-hint "Rime Enabled")
;; (cons +tab-bar-rime-inactive-hint "Rime Disabled"))
;; (cons +tab-bar-no-ime-hint "No IME"))))
;; `((tab-bar-rime menu-item
;; ,(car text-help)
;; ignore
;; :help ,(cdr text-help)))))
(defun +hide-tab-bar ()
(interactive)
(setq tab-bar-format nil))
(defun-call! +show-tab-bbar ()
(interactive)
(setq tab-bar-format '(tab-bar-format-tabs tab-bar-separator
tab-bar-format-align-right
;; +tab-bar-org-pomodoro-indicator
;; +tab-bar-copilot-icon
;; +tab-bar-telega-icon
;; +tab-bar-persp-indicator
;; meow-indicator
;; +tab-bar-rime-indicator
))
(tab-bar--update-tab-bar-lines))
;; WORKAROUND: fresh tab-bar for daemon
(when (daemonp)
(add-hook 'after-make-frame-functions
#'(lambda (&rest _) (force-mode-line-update))))
)
(defhydra window (
:hint nil ; 只显示注释字符串,不显示绑定信息
:color blue ; 执行完一次后就退出
:foreign-keys run ; 如果不在 hydra 按键内,则执行,并不退出 hydra
)
"
Tab^^ Winner^^ Resize^^ Desktop^^
-----------------------------------------------------------------------
[_c_] Switch [_u_] Undo [_=_] Enlarge [_s_] SaveDefault
[_0_] Close [_U_] Redo [_-_] Shrink [_l_] Load
[_2_] New ^ ^ [_+_] EnlargeV ^ ^
[_R_] Rename ^ ^ [___] ShrinkV [_q_] Quit
"
("c" tab-switch)
("0" tab-close)
("2" tab-new)
("R" tab-rename :color red)
("u" winner-undo :color red)
("U" winner-redo :color red)
("=" enlarge-window :color red)
("-" shrink-window :color red)
("+" enlarge-window-horizontally :color red)
("_" shrink-window-horizontally :color red)
("s" desktop-save-in-desktop-dir)
("l" desktop-read)
("q" nil))
(global-set-key (kbd "C-x t") 'window/body)