Commit c2ab5e8c authored by Juri Linkov's avatar Juri Linkov

* lisp/tab-line.el: Limit the number of window tabs to tab-line-tabs-limit.

parent f458ca28
Pipeline #3034 failed with stage
in 6 minutes and 2 seconds
...@@ -130,26 +130,45 @@ Reduce tab width proportionally to space taken by other tabs." ...@@ -130,26 +130,45 @@ Reduce tab width proportionally to space taken by other tabs."
(substring tab-name (- limit))) (substring tab-name (- limit)))
'help-echo tab-name)))) 'help-echo tab-name))))
(defun tab-line-format () (defvar tab-line-tabs-limit 15
"Template for displaying tab line for selected window." "Maximum number of buffer tabs displayed in the window tab-line.")
(let* ((window (selected-window))
(buffer (window-buffer window)) (defun tab-line-tabs (&optional window)
(let* ((buffer (window-buffer window))
(next-buffers (seq-remove (lambda (b) (eq b buffer)) (next-buffers (seq-remove (lambda (b) (eq b buffer))
(window-next-buffers window))) (window-next-buffers window)))
(next-buffers (seq-filter #'buffer-live-p next-buffers))
(prev-buffers (seq-remove (lambda (b) (eq b buffer)) (prev-buffers (seq-remove (lambda (b) (eq b buffer))
(mapcar #'car (window-prev-buffers window)))) (mapcar #'car (window-prev-buffers window))))
(prev-buffers (seq-filter #'buffer-live-p prev-buffers))
;; Remove next-buffers from prev-buffers ;; Remove next-buffers from prev-buffers
(prev-buffers (seq-difference prev-buffers next-buffers)) (prev-buffers (seq-difference prev-buffers next-buffers))
(buffers (append (reverse prev-buffers) (half-limit (/ tab-line-tabs-limit 2))
(list buffer) (prev-buffers-limit
next-buffers)) (if (> (length prev-buffers) half-limit)
(buffers (seq-filter #'buffer-live-p buffers))) (if (> (length next-buffers) half-limit)
half-limit
(+ half-limit (- half-limit (length next-buffers))))
(length prev-buffers)))
(next-buffers-limit
(- tab-line-tabs-limit prev-buffers-limit))
(buffer-tabs
(append (reverse (seq-take prev-buffers prev-buffers-limit))
(list buffer)
(seq-take next-buffers next-buffers-limit))))
buffer-tabs))
(defun tab-line-format ()
"Template for displaying tab line for selected window."
(let* ((window (selected-window))
(buffer (window-buffer window))
(buffer-tabs (tab-line-tabs window)))
(append (append
(mapcar (mapcar
(lambda (b) (lambda (b)
(format "%s%s%s" (format "%s%s%s"
tab-line-separator tab-line-separator
(apply 'propertize (tab-line-tab-name b buffers) (apply 'propertize (tab-line-tab-name b buffer-tabs)
`( `(
buffer ,b buffer ,b
face ,(if (eq b buffer) face ,(if (eq b buffer)
...@@ -166,7 +185,7 @@ Reduce tab width proportionally to space taken by other tabs." ...@@ -166,7 +185,7 @@ Reduce tab width proportionally to space taken by other tabs."
'tab-line-tab-inactive) 'tab-line-tab-inactive)
mouse-face tab-line-close-highlight mouse-face tab-line-close-highlight
keymap ,tab-line-tab-close-map)))) keymap ,tab-line-tab-close-map))))
buffers) buffer-tabs)
(list (format "%s%s" (list (format "%s%s"
tab-line-separator tab-line-separator
(apply 'propertize tab-line-tab-name-add (apply 'propertize tab-line-tab-name-add
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment