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

From: Elijah Gabe Pérez <[email-masked]>
Date: Sun, 03 Aug 2025 20:38:48 -0600

Eli Zaretskii <[email-masked]> writes:

>> From: Elijah Gabe Pérez <[email-masked]>
>> Date: Sat, 02 Aug 2025 14:00:27 -0600
>> 
>> 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.
>
> I think "makes no sense" is in the eyes of the beholder.  These
> variables determine which buffers should have the tab-line shown in
> their windows, they don't mean these buffers should not be reachable
> via the tab-line in other buffers.  Hiding them in all tab-lines means
> you cannot switch to those buffers except via "C-x b" or somesuch.
> That is not the intent of these variables, AFAIU.  Their intent is to
> disable tab-line in buffers where showing the tab-line makes no sense.
> The default value of tab-line-exclude-modes is a good example of that.

Of course, but the variable names can be confusing, some users familiar
with other tab-line-like packages might expect this feature.  This may
also depend on the users workflow; some may prefer to use the tab-line
to display only relevant tabs and search for the rest with "C-x b".

> But I won't object to adding a knob to have the behavior you want, if
> Juri agrees, and there are no other objections.  However, this must be
> an opt-in behavior, by default off.

Fine, I've added it as an option.

>> Currently, it only works for 'tab-line-tabs-fixed-window-buffers'.
>
> Which IMO is a limitation that should be lifted, for this feature to
> make sense.  I expect to see bug reports if we don't.

I've added it to the other relevant functions.

>> +*** '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'.
>
> A buffer cannot be "included" in a list of modes, so talking about a
> buffer included in tab-line-exclude-modes is confusing.  I suggest to
> reword:
>
>   *** Excluded buffers are no longer shown in tab-lines of other buffers.
>   Buffers that match 'tab-line-exclude-buffers' and buffers whose
>   modes are in 'tab-line-exclude-modes' will not appear in tab-lines
>   of other buffers.

> Also, why isn't there either "+++" (and a suitable change to the
> manual) or "---" for this entry?  We don't want to defer the decision
> whether and how to document the changes in the manuals to the time
> when a release will be prepared, we want to make the necessary
> documentation changes right away.  So let's please decide now whether
> this change deserves to be mentioned in the manuals, and act
> accordingly.

I forgot it, but i don't think this needs to be added to the manual,
mostly because none of the NEWS entries in "Tab Bars and Tab Lines" are
in the manual.

>From 14da64c8040717626d21866d28a63d025b888cce 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. 
 (Bug#79159)

* etc/NEWS: Announce changes.
* lisp/tab-line.el (tab-line-hide-excluded-buffers): New user
option.
(tab-line-displayable-tab-list): New function.
(tab-line-tabs-mode-buffers, tab-line-tabs-buffer-groups)
(tab-line-tabs-window-buffers)
(tab-line-tabs-fixed-window-buffers): Rework.
---
 etc/NEWS         |  6 ++++++
 lisp/tab-line.el | 51 ++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index e12a9dcb127..c4183c50095 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -436,6 +436,12 @@ 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.
 
+---
+***Excluded buffers are no longer shown in tab-lines of other buffers.
+Buffers that match 'tab-line-exclude-buffers' and buffers whose
+modes are in 'tab-line-exclude-modes' will not appear in tab-lines
+of other buffers.
+
 ** Project
 
 ---
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 51675dbbb29..98e1f4346a6 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -402,6 +402,23 @@ tab-line-tabs-buffer-list-function
   "Function to return a global list of buffers.
 Used only for `tab-line-tabs-mode-buffers' and `tab-line-tabs-buffer-groups'.")
 
+
+(defvar tab-line-hide-excluded-buffers)
+(defvar tab-line-exclude-modes)
+(defvar tab-line-exclude-buffers)
+
+(defun tab-line-displayable-tab-list (tabs)
+  "Return a list of displayable tabs from TABS.
+TABS must be a list of buffers."
+  (if tab-line-hide-excluded-buffers
+      (seq-remove
+       (lambda (b)
+         (or (with-current-buffer b
+               (memq major-mode tab-line-exclude-modes))
+             (buffer-match-p tab-line-exclude-buffers b)))
+       tabs)
+    tabs))
+
 (defun tab-line-tabs-buffer-list ()
   (seq-filter (lambda (b) (and (buffer-live-p b)
                                (/= (aref (buffer-name b) 0) ?\s)))
@@ -415,7 +432,8 @@ tab-line-tabs-mode-buffers
     (seq-sort-by #'buffer-name #'string<
                  (seq-filter (lambda (b) (with-current-buffer b
                                            (derived-mode-p mode)))
-                             (funcall tab-line-tabs-buffer-list-function)))))
+                             (tab-line-displayable-tab-list
+                              (funcall tab-line-tabs-buffer-list-function))))))
 
 (defun tab-line-tab-modified-p (tab buffer-p)
   "Return t if TAB is modified."
@@ -513,7 +531,8 @@ tab-line-tabs-buffer-groups
 If non-nil, `tab-line-tabs-buffer-group-function' is used to
 generate the group name."
   (if (window-parameter nil 'tab-line-groups)
-      (let* ((buffers (funcall tab-line-tabs-buffer-list-function))
+      (let* ((buffers (tab-line-displayable-tab-list
+                       (funcall tab-line-tabs-buffer-list-function)))
              (groups (delq nil
                            (mapcar #'car
                                    (seq-group-by #'tab-line-tabs-buffer-group-name
@@ -581,9 +600,18 @@ tab-line-tabs-window-buffers
          (prev-buffers (seq-filter #'buffer-live-p prev-buffers))
          ;; Remove next-buffers from prev-buffers
          (prev-buffers (seq-difference prev-buffers next-buffers)))
-    (append (reverse prev-buffers)
-            (list buffer)
-            next-buffers)))
+    (tab-line-displayable-tab-list
+     (append (reverse prev-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.
@@ -598,7 +626,9 @@ 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 (tab-line-displayable-tab-list
+                       (funcall tab-line-tabs-fixed-buffer-list-function)))
+         (new-buffers (sort buffer-list
                             :in-place t
                             :key (lambda (buffer)
                                    (gethash buffer buffer-positions
@@ -1316,6 +1346,15 @@ tab-line-exclude-buffers
   :group 'tab-line
   :version "31.1")
 
+(defcustom tab-line-hide-excluded-buffers nil
+  "Whether the excluded buffers should not appear in the tab line.
+If non-nil, buffers that match `tab-line-exclude-buffers' and buffers
+whose modes are in `tab-line-exclude-modes' will not appear in
+tab-lines."
+  :type 'boolean
+  :group 'tab-line
+  :version "31.1")
+
 ;;;###autoload
 (defvar-local tab-line-exclude nil)
 
-- 
2.50.1

-- 
- E.G via Gnus and Org.