From c5cd23ddbf2c8c5b96f4d07cb04a24e9f78c96b2 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Fri, 24 Sep 2021 04:47:56 +0000 Subject: [PATCH] * lisp/tab-line.el: Add modified-buffer face (tab-line-tab-modified): New face. (tab-line-tab-face-modified): New function. (tab-line-tab-face-functions): Use new function. * etc/NEWS: Update. --- etc/NEWS | 14 ++++++++------ lisp/tab-line.el | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b0e2d2c060..06e2e4f3eb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -529,12 +529,14 @@ the mouse pointer is in the tab line by scrolling left or right. *** New tab-line faces and options. The face 'tab-line-tab-special' is used for tabs whose buffers are special, i.e. buffers that don't visit a file. The face -'tab-line-tab-inactive-alternate' is used to display inactive tabs -with an alternating background color, making them easier to -distinguish, especially if the face 'tab-line-tab' is configured to -not display with a box; this alternate face is only applied when the -option 'tab-line-tab-face-functions' is so configured. That option -may also be used to customize tab-line faces in other ways. +'tab-line-tab-modified' is used to display modified, file-backed +buffers. The face 'tab-line-tab-inactive-alternate' is used to +display inactive tabs with an alternating background color, making +them easier to distinguish, especially if the face 'tab-line-tab' is +configured to not display with a box; this alternate face is only +applied when the option 'tab-line-tab-face-functions' is so +configured. That option may also be used to customize tab-line faces +in other ways. ** Mouse wheel diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 1f7af9e9a9..4a751b384e 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -36,13 +36,15 @@ tab-line :group 'convenience :version "27.1") -(defcustom tab-line-tab-face-functions '(tab-line-tab-face-special) +(defcustom tab-line-tab-face-functions + '(tab-line-tab-face-modified 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-modified) (function-item tab-line-tab-face-inactive-alternating) (function-item tab-line-tab-face-group) (function :tag "Custom function"))) @@ -92,6 +94,14 @@ tab-line-tab-special :version "28.1" :group 'tab-line-faces) +(defface tab-line-tab-modified + '((t :inherit font-lock-doc-face)) + "Face for modified tabs. +Applied when option `tab-line-tab-face-functions' includes +function `tab-line-tab-face-modified'." + :version "28.1" + :group 'tab-line-faces) + (defface tab-line-tab-group '((t :inherit tab-line :box nil)) "Face for group tabs. @@ -537,6 +547,15 @@ tab-line-tab-face-special (setf face `(:inherit (tab-line-tab-special ,face)))) face) +(defun tab-line-tab-face-modified (tab _tabs face buffer-p _selected-p) + "Return FACE for TAB according to whether it's modified. +When TAB is a modified, file-backed buffer, make FACE inherit +from `tab-line-tab-modified'. For use in +`tab-line-tab-face-functions'." + (when (and buffer-p (buffer-file-name tab) (buffer-modified-p tab)) + (setf face `(:inherit (tab-line-tab-modified ,face)))) + face) + (defun tab-line-tab-face-group (tab _tabs face _buffer-p _selected-p) "Return FACE for TAB according to whether it's a group tab. For use in `tab-line-tab-face-functions'." -- 2.20.1