From: Adam Porter <adam@alphapapa.net>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] tab-line-alternate-colors
Date: Sun, 13 Dec 2020 05:13:45 -0600 [thread overview]
Message-ID: <87pn3et0uu.fsf@alphapapa.net> (raw)
In-Reply-To: 87tusqt3yr.fsf@alphapapa.net
[-- Attachment #1: Type: text/plain, Size: 825 bytes --]
> Yes, that seems like a good idea. Something like this? I also added
> another face for non-file-backed buffers, which helps distinguish
> them.
The attached patch fixes a bug with an anonymous face in the previous
patch.
By the way, it seems that, because the face `tab-line' inherits from the
face `variable-pitch', an anonymous face that inherits from
`tab-line-tab-special' (which defaults to italic slant in this patch) is
prevented from having italic slant applied. If I set `tab-line' to not
inherit from `variable-pitch', the italic slant is inherited.
`variable-pitch' has not been customized, so it has no value for the
slant attribute, so it seems like it shouldn't interfere. I don't know
if this is a bug in my code, in Emacs 28, or in the native-comp branch
that I'm using to develop this patch.
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 4940 bytes --]
From dc4723fefa5d77eb28a6d2b67afdf5e5b8e696d7 Mon Sep 17 00:00:00 2001
From: Adam Porter <adam@alphapapa.net>
Date: Sun, 13 Dec 2020 05:54:28 +0000
Subject: [PATCH] New tab-line options, faces, and face function
* lisp/tab-line.el:
(tab-line-tab-face-function): New option.
(tab-line-alternate-colors): New option.
(tab-line-tab-inactive-alternate): New face.
(tab-line-tab-special): New face.
(tab-line-tab-face-default): New function.
(tab-line-format-template): Use them.
Thanks to Juri Linkov for his feedback.
---
lisp/tab-line.el | 75 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 69 insertions(+), 6 deletions(-)
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 46bf89f14e..640c568cc5 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,22 @@ tab-line
:group 'convenience
:version "27.1")
+(defcustom tab-line-alternate-colors t
+ "Alternate background colors of inactive tabs.
+When non-nil, alternating tabs use the face
+`tab-line-tab-inactive-alternate'."
+ :type 'boolean
+ :group 'tab-line
+ :version "28.1")
+
+(defcustom tab-line-tab-face-function #'tab-line-tab-face-default
+ "Function called to get a tab's face.
+The function is called with two arguments: the tab and a list of
+all tabs."
+ :type '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 +80,19 @@ tab-line-tab-inactive
:version "27.1"
:group 'tab-line-faces)
+(defface tab-line-tab-inactive-alternate
+ (let ((mode-line-bg (face-background 'mode-line nil t)))
+ `((t (:inherit tab-line-tab-inactive :background ,mode-line-bg))))
+ "Alternate face for inactive tab-line tabs.
+Used on alternating tabs when `tab-line-alternate-colors' is non-nil."
+ :version "28.1"
+ :group 'tab-line-faces)
+
+(defface tab-line-tab-special '((t (:slant italic)))
+ "Face for special (i.e. non-file-backed) tabs."
+ :version "28.1"
+ :group 'tab-line-faces)
+
(defface tab-line-tab-current
'((default
:inherit tab-line-tab)
@@ -412,7 +442,9 @@ 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 (funcall tab-line-tab-face-function
+ tab tabs)))
(concat
separator
(apply 'propertize
@@ -425,11 +457,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 +481,41 @@ tab-line-format-template
tab-line-new-button)
(list tab-line-new-button)))))
+(defun tab-line-tab-face-default (tab tabs)
+ "Return face for TAB in TABS.
+If TAB is selected, return `tab-line-tab-current' if the tab's
+window is also selected, otherwise `tab-line-tab'.
+
+Otherwise, if `tab-line-alternate-colors' is non-nil, return
+`tab-line-tab-inactive-alternate' for even-numbered tabs and
+`tab-line-tab-inactive' for odd-numbered ones.
+
+Otherwise, return `tab-line-tab-inactive'.
+
+If the tab's buffer is not file-backed, the returned face also
+inherits from `tab-line-tab-special'.
+
+For use as `tab-line-tab-face-function'."
+ (let* ((buffer-p (bufferp tab))
+ (selected-p (if buffer-p
+ (eq tab (window-buffer))
+ (cdr (assq 'selected tab))))
+ (face (cond (selected-p
+ (if (eq (selected-window) (old-selected-window))
+ 'tab-line-tab-current
+ 'tab-line-tab))
+ ((and tab-line-alternate-colors
+ (cl-evenp (cl-position tab tabs)))
+ 'tab-line-tab-inactive-alternate)
+ (t
+ 'tab-line-tab-inactive))))
+ (if (and buffer-p (not (buffer-file-name tab)))
+ ;; FIXME: The `tab-line' face's inheriting from
+ ;; `variable-pitch' seems to prevent inheriting from
+ ;; `tab-line-tab-special' applying italic slant.
+ `(:inherit (tab-line-tab-special ,face))
+ face)))
+
(defvar tab-line-auto-hscroll)
(defun tab-line-format ()
--
2.20.1
next prev parent reply other threads:[~2020-12-13 11:13 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 [this message]
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
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=87pn3et0uu.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.