Subject: bug#79159: [PATCH] Do not display in the tab line tabs that are excluded.

From: Elijah Gabe Pérez <[email-masked]>
Date: Sat, 02 Aug 2025 14:00:27 -0600

Tags: patch

tab-line by default displays all the tabs in the tab line, however this
also includes the tab that are excluded in 'tab-line-exclude-modes' and
'tab-line-exclude-buffers', which IMO makes no sense.

The patch attached, solves this.

Currently, it only works for 'tab-line-tabs-fixed-window-buffers'.

>From fa84b8e93802e16fdfba1f9cc79e076da8d25527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Fri, 1 Aug 2025 20:14:59 -0600
Subject: [PATCH] Do not display in the tab line tabs that are excluded.

* etc/NEWS: Announce changes.
* lisp/tab-line.el (tab-line-tabs-fixed-buffer-list-function):
New variable.
(tab-line-tabs-fixed-window-buffers): Rework for hide the
excluded tabs.  (Bug#)
---
 etc/NEWS         |  5 +++++
 lisp/tab-line.el | 16 +++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 36a9bf39d55..dc2f0c819fb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -432,6 +432,11 @@ a buffer.  The value must be a condition which is passed to
 With this user option, if non-nil (the default), the tab close button
 will change its appearance if the tab buffer has been modified.
 
+*** 'tab-line-tabs-fixed-window-buffers' now hides the excluded tabs.
+All the buffers included in 'tab-line-exclude-buffers' and
+'tab-line-exclude-modes' will not appear in the tab line only if
+'tab-line-tabs-function' is set to 'tab-line-tabs-fixed-window-buffers'.
+
 ** Project
 
 ---
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 51675dbbb29..ff05f5d83c0 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -585,6 +585,14 @@ tab-line-tabs-window-buffers
             (list buffer)
             next-buffers)))
 
+(defvar tab-line-tabs-fixed-buffer-list-function
+  #'tab-line-tabs-window-buffers
+  "Function for get a list of window buffers.
+Used only for `tab-line-tabs-fixed-window-buffers'.")
+
+(defvar tab-line-exclude-buffers)
+(defvar tab-line-exclude-modes)
+
 (defun tab-line-tabs-fixed-window-buffers ()
   "Like `tab-line-tabs-window-buffers' but keep stable sorting order.
 This means that switching to a buffer previously shown in the same
@@ -598,7 +606,13 @@ tab-line-tabs-fixed-window-buffers
                               (lambda (buf idx) (puthash buf idx index-table))
                               old-buffers)
                              index-table))
-         (new-buffers (sort (tab-line-tabs-window-buffers)
+         (buffer-list (seq-remove
+                       (lambda (b)
+                         (or (with-current-buffer b
+                               (memq major-mode tab-line-exclude-modes))
+                             (buffer-match-p tab-line-exclude-buffers b)))
+                       (funcall tab-line-tabs-fixed-buffer-list-function)))
+         (new-buffers (sort buffer-list
                             :in-place t
                             :key (lambda (buffer)
                                    (gethash buffer buffer-positions
-- 
2.50.1

-- 
- E.G via Gnus and Org.