From: Juri Linkov Date: Mon, 2 Sep 2019 22:29:07 +0000 (+0300) Subject: * lisp/tab-line.el: Limit the number of window tabs to tab-line-tabs-limit. X-Git-Tag: emacs-27.0.90~1328^2~19 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c2ab5e8cf3654e3e13083fb2203502d5d5f49dc6;p=emacs.git * lisp/tab-line.el: Limit the number of window tabs to tab-line-tabs-limit. --- diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 235cff19d97..da85925ff55 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -130,26 +130,45 @@ Reduce tab width proportionally to space taken by other tabs." (substring tab-name (- limit))) 'help-echo tab-name)))) -(defun tab-line-format () - "Template for displaying tab line for selected window." - (let* ((window (selected-window)) - (buffer (window-buffer window)) +(defvar tab-line-tabs-limit 15 + "Maximum number of buffer tabs displayed in the window tab-line.") + +(defun tab-line-tabs (&optional window) + (let* ((buffer (window-buffer window)) (next-buffers (seq-remove (lambda (b) (eq b buffer)) (window-next-buffers window))) + (next-buffers (seq-filter #'buffer-live-p next-buffers)) (prev-buffers (seq-remove (lambda (b) (eq b buffer)) (mapcar #'car (window-prev-buffers window)))) + (prev-buffers (seq-filter #'buffer-live-p prev-buffers)) ;; Remove next-buffers from prev-buffers (prev-buffers (seq-difference prev-buffers next-buffers)) - (buffers (append (reverse prev-buffers) - (list buffer) - next-buffers)) - (buffers (seq-filter #'buffer-live-p buffers))) + (half-limit (/ tab-line-tabs-limit 2)) + (prev-buffers-limit + (if (> (length prev-buffers) half-limit) + (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 (mapcar (lambda (b) (format "%s%s%s" tab-line-separator - (apply 'propertize (tab-line-tab-name b buffers) + (apply 'propertize (tab-line-tab-name b buffer-tabs) `( buffer ,b face ,(if (eq b buffer) @@ -166,7 +185,7 @@ Reduce tab width proportionally to space taken by other tabs." 'tab-line-tab-inactive) mouse-face tab-line-close-highlight keymap ,tab-line-tab-close-map)))) - buffers) + buffer-tabs) (list (format "%s%s" tab-line-separator (apply 'propertize tab-line-tab-name-add