@@ -213,9 +213,6 @@ If nil, don't show it at all."
213
213
214
214
(defvar tab-line-separator nil )
215
215
216
- (defvar tab-line-tab-name-ellipsis
217
- (if (char-displayable-p ?… ) " …" " ..." ))
218
-
219
216
220
217
(defcustom tab-line-tab-name-function #'tab-line-tab-name-buffer
221
218
" Function to get a tab name.
@@ -240,23 +237,30 @@ This function can be overridden by changing the default value of the
240
237
variable `tab-line-tab-name-function' ."
241
238
(buffer-name buffer))
242
239
243
- (defun tab-line-tab-name-truncated-buffer (buffer &optional buffers )
240
+ (defcustom tab-line-tab-name-truncated-max 20
241
+ " Maximum length of the tab name from the current buffer.
242
+ Effective when `tab-line-tab-name-function' is customized
243
+ to `tab-line-tab-name-truncated-buffer' ."
244
+ :type 'integer
245
+ :group 'tab-line
246
+ :version " 27.1" )
247
+
248
+ (defvar tab-line-tab-name-ellipsis
249
+ (if (char-displayable-p ?… ) " …" " ..." ))
250
+
251
+ (defun tab-line-tab-name-truncated-buffer (buffer &optional _buffers )
244
252
" Generate tab name from BUFFER.
245
- Reduce tab width proportionally to space taken by other tabs."
246
- (let ((tab-name (buffer-name buffer))
247
- (limit (when buffers
248
- (max 1 (- (/ (window-width ) (length buffers)) 3 )))))
249
- (if (or (not limit) (< (length tab-name) limit))
253
+ Truncate it to the length specified by `tab-line-tab-name-truncated-max' .
254
+ Append ellipsis `tab-line-tab-name-ellipsis' in this case."
255
+ (let ((tab-name (buffer-name buffer)))
256
+ (if (< (length tab-name) tab-line-tab-name-truncated-max)
250
257
tab-name
251
- (propertize (truncate-string-to-width tab-name limit nil nil
252
- tab-line-tab-name-ellipsis)
258
+ (propertize (truncate-string-to-width
259
+ tab-name tab-line-tab-name-truncated-max nil nil
260
+ tab-line-tab-name-ellipsis)
253
261
'help-echo tab-name))))
254
262
255
263
256
- (defvar tab-line-tabs-limit nil
257
- " Maximum number of buffer tabs displayed in the tab line.
258
- If nil, no limit." )
259
-
260
264
(defcustom tab-line-tabs-function #'tab-line-tabs-window-buffers
261
265
" Function to get a list of tabs to display in the tab line.
262
266
This function should return either a list of buffers whose names will
@@ -395,22 +399,9 @@ variable `tab-line-tabs-function'."
395
399
(prev-buffers (seq-filter #'buffer-live-p prev-buffers))
396
400
; ; Remove next-buffers from prev-buffers
397
401
(prev-buffers (seq-difference prev-buffers next-buffers)))
398
- (if (natnump tab-line-tabs-limit)
399
- (let* ((half-limit (/ tab-line-tabs-limit 2 ))
400
- (prev-buffers-limit
401
- (if (> (length prev-buffers) half-limit)
402
- (if (> (length next-buffers) half-limit)
403
- half-limit
404
- (+ half-limit (- half-limit (length next-buffers))))
405
- (length prev-buffers)))
406
- (next-buffers-limit
407
- (- tab-line-tabs-limit prev-buffers-limit)))
408
- (append (reverse (seq-take prev-buffers prev-buffers-limit))
409
- (list buffer)
410
- (seq-take next-buffers next-buffers-limit)))
411
- (append (reverse prev-buffers)
412
- (list buffer)
413
- next-buffers))))
402
+ (append (reverse prev-buffers)
403
+ (list buffer)
404
+ next-buffers)))
414
405
415
406
416
407
(defun tab-line-format-template (tabs )
@@ -681,15 +672,17 @@ Its effect is the same as using the `next-buffer' command
681
672
(switch-to-buffer buffer)))))))
682
673
683
674
684
- (defcustom tab-line-close-tab-action 'bury-buffer
675
+ (defcustom tab-line-close-tab-function 'bury-buffer
685
676
" Defines what to do on closing the tab.
686
677
If `bury-buffer' , put the tab's buffer at the end of the list of all
687
678
buffers that effectively hides the buffer's tab from the tab line.
688
679
If `kill-buffer' , kills the tab's buffer.
680
+ When a function, it is called with the tab as its argument.
689
681
This option is useful when `tab-line-tabs-function' has the value
690
682
`tab-line-tabs-window-buffers' ."
691
683
:type '(choice (const :tag " Bury buffer" bury-buffer)
692
- (const :tag " Kill buffer" kill-buffer))
684
+ (const :tag " Kill buffer" kill-buffer)
685
+ (function :tag " Function" ))
693
686
:group 'tab-line
694
687
:version " 27.1" )
695
688
@@ -703,18 +696,20 @@ from the tab line."
703
696
(window (and posnp (posn-window posnp)))
704
697
(tab (get-pos-property 1 'tab (car (posn-string posnp))))
705
698
(buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))
706
- (close-action (unless (bufferp tab) (cdr (assq 'close tab)))))
699
+ (close-function (unless (bufferp tab) (cdr (assq 'close tab)))))
707
700
(with-selected-window (or window (selected-window ))
708
701
(cond
709
- ((functionp close-action )
710
- (funcall close-action ))
711
- ((eq tab-line-close-tab-action 'kill-buffer )
702
+ ((functionp close-function )
703
+ (funcall close-function ))
704
+ ((eq tab-line-close-tab-function 'kill-buffer )
712
705
(kill-buffer buffer))
713
- ((eq tab-line-close-tab-action 'bury-buffer )
706
+ ((eq tab-line-close-tab-function 'bury-buffer )
714
707
(if (eq buffer (current-buffer ))
715
708
(bury-buffer )
716
709
(set-window-prev-buffers nil (assq-delete-all buffer (window-prev-buffers )))
717
- (set-window-next-buffers nil (delq buffer (window-next-buffers ))))))
710
+ (set-window-next-buffers nil (delq buffer (window-next-buffers )))))
711
+ ((functionp tab-line-close-tab-function)
712
+ (funcall tab-line-close-tab-function)))
718
713
(force-mode-line-update ))))
719
714
720
715
0 commit comments