all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] tab-line-alternate-colors
Date: Wed, 16 Dec 2020 04:26:02 -0600	[thread overview]
Message-ID: <87zh2evyh1.fsf@alphapapa.net> (raw)
In-Reply-To: 87a6ueruko.fsf@mail.linkov.net

[-- Attachment #1: Type: text/plain, Size: 1344 bytes --]

Juri Linkov <juri@linkov.net> writes:

> Thanks, everything looks right.  The only thing I'm unsure about is
> the default value.  I don't know how important is to highlight the
> distinction between file and non-file buffers.  But it's a matter of
> taste, so I can't argue against or for a specific default value.

I don't know how important it is, either.  :)  But I think it's very
helpful for distinguishing buffers, especially in the smaller text of
the tab-line.  It seems to me that it does no harm, and it seems more
useful than not, so it seems that it might as well be the default.

> Ideally, the default value should reflect preferences of the most
> users, but even the conducted surveys don't help, as the discussion
> about the toolbar indicates.

I don't think we should use design-by-committee for every option, even
if we could.  To a certain extent, users won't know what they want until
they try it (cf. Ford's famous saying about asking his customers what
they wanted).  I think we should set the most useful defaults, and users
can customize to their taste.

That's my opinion, anyway.  I'll adjust the patch according to whatever
you or Eli think is best.  Let me know.

By the way, the attached patch tidies up a couple of things, including
removing a FIXME that seems to be not a bug after all.

Thanks for your help.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 5095 bytes --]

From df2b42fa06651d93267954aa9af6fb3cff90fb0f Mon Sep 17 00:00:00 2001
From: Adam Porter <adam@alphapapa.net>
Date: Sun, 13 Dec 2020 05:54:28 +0000
Subject: [PATCH] tab-line: New faces and functions

* lisp/tab-line.el:
(tab-line-tab-face-function): New option.
(tab-line-tab-face-functions): New option.
(tab-line-tab-inactive-alternate): New face.
(tab-line-tab-special): New face.
(tab-line-tab-face-inactive-alternating): New function.
(tab-line-tab-face-special): New function.
(tab-line-format-template): Use new function.

Thanks to Juri Linkov and Eli Zaretskii for their guidance.
---
 lisp/tab-line.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 46bf89f..c944471 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (require 'seq) ; tab-line.el is not pre-loaded so it's safe to use it here
 
 \f
@@ -35,6 +36,18 @@ tab-line
   :group 'convenience
   :version "27.1")
 
+(defcustom tab-line-tab-face-functions '(tab-line-tab-face-special)
+  "Functions called to modify tab faces.
+Each function is called with five arguments: the tab, a list of
+all tabs, the face returned by the previously called modifier,
+whether the tab is a buffer, and whether the tab is selected."
+  :type '(repeat
+          (choice (function-item tab-line-tab-face-special)
+                  (function-item tab-line-tab-face-inactive-alternating)
+                  (function :tag "Custom function")))
+  :group 'tab-line
+  :version "28.1")
+
 (defgroup tab-line-faces '((tab-line custom-face)) ; tab-line is defined in faces.el
   "Faces used in the tab line."
   :group 'tab-line
@@ -63,6 +76,25 @@ tab-line-tab-inactive
   :version "27.1"
   :group 'tab-line-faces)
 
+(defface tab-line-tab-inactive-alternate
+  `((t (:inherit tab-line-tab-inactive :background "grey65")))
+  "Alternate face for inactive tab-line tabs.
+Applied to alternating tabs when option
+`tab-line-tab-face-functions' includes function
+`tab-line-tab-face-inactive-alternating'."
+  :version "28.1"
+  :group 'tab-line-faces)
+
+(defface tab-line-tab-special
+  '((default (:weight bold))
+    (((supports :slant italic))
+     (:slant italic :weight normal)))
+  "Face for special (i.e. non-file-backed) tabs.
+Applied when option `tab-line-tab-face-functions' includes
+function `tab-line-tab-face-special'."
+  :version "28.1"
+  :group 'tab-line-faces)
+
 (defface tab-line-tab-current
   '((default
       :inherit tab-line-tab)
@@ -412,7 +444,14 @@ tab-line-format-template
                                   (cdr (assq 'selected tab))))
                     (name (if buffer-p
                               (funcall tab-line-tab-name-function tab tabs)
-                            (cdr (assq 'name tab)))))
+                            (cdr (assq 'name tab))))
+                    (face (if selected-p
+                              (if (eq (selected-window) (old-selected-window))
+                                  'tab-line-tab-current
+                                'tab-line-tab)
+                            'tab-line-tab-inactive)))
+               (dolist (fn tab-line-tab-face-functions)
+                 (setf face (funcall fn tab tabs face buffer-p selected-p)))
                (concat
                 separator
                 (apply 'propertize
@@ -425,11 +464,7 @@ tab-line-format-template
                        `(
                          tab ,tab
                          ,@(if selected-p '(selected t))
-                         face ,(if selected-p
-                                   (if (eq (selected-window) (old-selected-window))
-                                       'tab-line-tab-current
-                                     'tab-line-tab)
-                                 'tab-line-tab-inactive)
+                         face ,face
                          mouse-face tab-line-highlight)))))
            tabs))
          (hscroll-data (tab-line-auto-hscroll strings hscroll)))
@@ -453,6 +488,24 @@ tab-line-format-template
                 tab-line-new-button)
        (list tab-line-new-button)))))
 
+(defun tab-line-tab-face-inactive-alternating (tab tabs face _buffer-p selected-p)
+  "Return FACE for TAB in TABS with alternation.
+When TAB is an inactive buffer and is even-numbered, make FACE
+inherit from `tab-line-tab-inactive-alternate'.  For use in
+`tab-line-tab-face-functions'."
+  (when (and (not selected-p) (cl-evenp (cl-position tab tabs)))
+    (setf face `(:inherit (tab-line-tab-inactive-alternate ,face))))
+  face)
+
+(defun tab-line-tab-face-special (tab _tabs face buffer-p _selected-p)
+  "Return FACE for TAB according to whether it's special.
+When TAB is a non-file-backed buffer, make FACE inherit from
+`tab-line-tab-special'.  For use in
+`tab-line-tab-face-functions'."
+  (when (and buffer-p (not (buffer-file-name tab)))
+    (setf face `(:inherit (tab-line-tab-special ,face))))
+  face)
+
 (defvar tab-line-auto-hscroll)
 
 (defun tab-line-format ()
-- 
2.7.4


  reply	other threads:[~2020-12-16 10:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13  6:04 [PATCH] tab-line-alternate-colors Adam Porter
2020-12-13  6:17 ` Adam Porter
2020-12-13  8:45 ` Juri Linkov
2020-12-13 10:06   ` Adam Porter
2020-12-13 11:13     ` Adam Porter
2020-12-13 15:21     ` Eli Zaretskii
2020-12-14  2:17       ` Adam Porter
2020-12-14 15:34         ` Eli Zaretskii
2020-12-16  2:58           ` Adam Porter
2020-12-16 15:41             ` Eli Zaretskii
2020-12-13 21:25     ` Juri Linkov
2020-12-14  4:33       ` Adam Porter
2020-12-14  9:10         ` Juri Linkov
2020-12-14 10:05           ` Adam Porter
2020-12-14 19:37             ` Juri Linkov
2020-12-16  3:24               ` Adam Porter
2020-12-16  3:55                 ` Adam Porter
2020-12-16  9:03                 ` Juri Linkov
2020-12-16 10:26                   ` Adam Porter [this message]
2020-12-16 20:46                     ` Juri Linkov
2020-12-18  3:55                       ` Adam Porter
2020-12-23 21:07                         ` Juri Linkov
2020-12-24 11:26                           ` Adam Porter
2020-12-14  9:14         ` Adam Porter
2020-12-14 19:33           ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zh2evyh1.fsf@alphapapa.net \
    --to=adam@alphapapa.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.