>From 93fb347ada44b34d8e656b33fdd62e3b786cf8a1 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 13 Dec 2020 05:54:28 +0000 Subject: [PATCH] New option `tab-line-alternate-colors` and associated face * lisp/tab-line.el: (tab-line-alternate-colors): New option. (tab-line-tab-inactive-alternate): New face. (tab-line-format-template): Use them. --- lisp/tab-line.el | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 46bf89f14e..9719a42da3 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 @@ -35,6 +36,14 @@ 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") + (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 +72,14 @@ 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-current '((default :inherit tab-line-tab) @@ -403,6 +420,7 @@ tab-line-format-template (let* ((selected-buffer (window-buffer)) (separator (or tab-line-separator (if window-system " " "|"))) (hscroll (window-parameter nil 'tab-line-hscroll)) + (tab-number 0) (strings (mapcar (lambda (tab) @@ -412,7 +430,16 @@ 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 (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-incf tab-number))) + 'tab-line-tab-inactive-alternate) + (t + 'tab-line-tab-inactive)))) (concat separator (apply 'propertize @@ -425,11 +452,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))) -- 2.20.1