unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] tab-line: New tab-line-tab-face-modified face
@ 2021-09-24  4:57 Adam Porter
  2021-09-24  6:38 ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Porter @ 2021-09-24  4:57 UTC (permalink / raw)
  To: emacs-devel

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

Hi Juri, et al,

Spending some more time using Emacs 28.0.50 with tab-bar and tab-line, I
found myself missing the ability to look at a tab-line tab and know
whether its buffer is modified (e.g. after using
`xref-query-replace-in-results' on some project buffers).

This patch adds a face for modified, file-backed buffers.  I chose to
inherit from the font-lock-doc-face, as it seems readable and intuitive
with the default theme.  It seems to make the tab-line much more useful,
and more in line with what users will probably expect from having used
other editors' GUIs.

-- 
Thanks,
Adam

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch adding tab-line-tab-face-modified --]
[-- Type: text/x-diff, Size: 3834 bytes --]

From c5cd23ddbf2c8c5b96f4d07cb04a24e9f78c96b2 Mon Sep 17 00:00:00 2001
From: Adam Porter <adam@alphapapa.net>
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24  4:57 [PATCH] tab-line: New tab-line-tab-face-modified face Adam Porter
@ 2021-09-24  6:38 ` Juri Linkov
  2021-09-24  7:09   ` Adam Porter
  0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2021-09-24  6:38 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-devel

> Spending some more time using Emacs 28.0.50 with tab-bar and tab-line, I
> found myself missing the ability to look at a tab-line tab and know
> whether its buffer is modified (e.g. after using
> `xref-query-replace-in-results' on some project buffers).
>
> This patch adds a face for modified, file-backed buffers.  I chose to
> inherit from the font-lock-doc-face, as it seems readable and intuitive
> with the default theme.  It seems to make the tab-line much more useful,
> and more in line with what users will probably expect from having used
> other editors' GUIs.

Thanks, a modified buffer needs to be indicated somehow,
but all other editors' GUIs display ‘*’ at the beginning
of the modified buffer's name.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24  6:38 ` Juri Linkov
@ 2021-09-24  7:09   ` Adam Porter
  2021-09-24 10:29     ` Stefan Kangas
  2021-09-24 15:42     ` Juri Linkov
  0 siblings, 2 replies; 8+ messages in thread
From: Adam Porter @ 2021-09-24  7:09 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> Spending some more time using Emacs 28.0.50 with tab-bar and tab-line, I
>> found myself missing the ability to look at a tab-line tab and know
>> whether its buffer is modified (e.g. after using
>> `xref-query-replace-in-results' on some project buffers).
>>
>> This patch adds a face for modified, file-backed buffers.  I chose to
>> inherit from the font-lock-doc-face, as it seems readable and intuitive
>> with the default theme.  It seems to make the tab-line much more useful,
>> and more in line with what users will probably expect from having used
>> other editors' GUIs.
>
> Thanks, a modified buffer needs to be indicated somehow,
> but all other editors' GUIs display ‘*’ at the beginning
> of the modified buffer's name.

Some do, yes, but I've used some that change the appearance of the text
in the tab's name, e.g. making it bold, italic, etc.  We already use
italic for non-file-backed buffers, and bold seems, well, too bold, IMHO
(and it may change the width of the tab with proportional fonts), so
changing the color seems reasonable.

I'm not opposed to optionally adding an asterisk to the name, but that
would change the width of the tab as soon as a user types into a buffer,
which doesn't seem like a good default to me.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24  7:09   ` Adam Porter
@ 2021-09-24 10:29     ` Stefan Kangas
  2021-09-24 15:42     ` Juri Linkov
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Kangas @ 2021-09-24 10:29 UTC (permalink / raw)
  To: Adam Porter, emacs-devel

Adam Porter <adam@alphapapa.net> writes:

> I'm not opposed to optionally adding an asterisk to the name, but that
> would change the width of the tab as soon as a user types into a buffer,
> which doesn't seem like a good default to me.

FWIW, I'm not too excited about tabs that change their width depending
on the buffer name.

I would prefer a fixed width like in Firefox, where tabs only get
smaller when it's needed to make room for more tabs.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24  7:09   ` Adam Porter
  2021-09-24 10:29     ` Stefan Kangas
@ 2021-09-24 15:42     ` Juri Linkov
  2021-09-24 22:13       ` Adam Porter
  1 sibling, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2021-09-24 15:42 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-devel

>>> Spending some more time using Emacs 28.0.50 with tab-bar and tab-line, I
>>> found myself missing the ability to look at a tab-line tab and know
>>> whether its buffer is modified (e.g. after using
>>> `xref-query-replace-in-results' on some project buffers).
>>>
>>> This patch adds a face for modified, file-backed buffers.  I chose to
>>> inherit from the font-lock-doc-face, as it seems readable and intuitive
>>> with the default theme.  It seems to make the tab-line much more useful,
>>> and more in line with what users will probably expect from having used
>>> other editors' GUIs.
>>
>> Thanks, a modified buffer needs to be indicated somehow,
>> but all other editors' GUIs display ‘*’ at the beginning
>> of the modified buffer's name.
>
> Some do, yes, but I've used some that change the appearance of the text
> in the tab's name, e.g. making it bold, italic, etc.  We already use
> italic for non-file-backed buffers, and bold seems, well, too bold, IMHO
> (and it may change the width of the tab with proportional fonts), so
> changing the color seems reasonable.
>
> I'm not opposed to optionally adding an asterisk to the name, but that
> would change the width of the tab as soon as a user types into a buffer,
> which doesn't seem like a good default to me.

I see another problem with an asterisk: many buffers already have an asterisk
as the first character of their buffer names, so it will be indistinguishable
from the modified status.

But why font-lock-doc-face?  Have you tried to change tab background color?
I guess this would be more visually pleasing.  Or maybe not.  This needs
more experimentation.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24 15:42     ` Juri Linkov
@ 2021-09-24 22:13       ` Adam Porter
  2021-09-25 19:18         ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: Adam Porter @ 2021-09-24 22:13 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

>>>> Spending some more time using Emacs 28.0.50 with tab-bar and tab-line, I
>>>> found myself missing the ability to look at a tab-line tab and know
>>>> whether its buffer is modified (e.g. after using
>>>> `xref-query-replace-in-results' on some project buffers).
>>>>
>>>> This patch adds a face for modified, file-backed buffers.  I chose to
>>>> inherit from the font-lock-doc-face, as it seems readable and intuitive
>>>> with the default theme.  It seems to make the tab-line much more useful,
>>>> and more in line with what users will probably expect from having used
>>>> other editors' GUIs.
>>>
>>> Thanks, a modified buffer needs to be indicated somehow,
>>> but all other editors' GUIs display ‘*’ at the beginning
>>> of the modified buffer's name.
>>
>> Some do, yes, but I've used some that change the appearance of the text
>> in the tab's name, e.g. making it bold, italic, etc.  We already use
>> italic for non-file-backed buffers, and bold seems, well, too bold, IMHO
>> (and it may change the width of the tab with proportional fonts), so
>> changing the color seems reasonable.
>>
>> I'm not opposed to optionally adding an asterisk to the name, but that
>> would change the width of the tab as soon as a user types into a buffer,
>> which doesn't seem like a good default to me.
>
> I see another problem with an asterisk: many buffers already have an asterisk
> as the first character of their buffer names, so it will be indistinguishable
> from the modified status.

Yes, good point.

> But why font-lock-doc-face?  Have you tried to change tab background color?
> I guess this would be more visually pleasing.  Or maybe not.  This needs
> more experimentation.

Because in the default theme, it results in text that's a dark red,
which is easily distinguished against the default tab background color,
while still being readable (IMHO).  It reminds me of other editors I've
used that use the red color to indicate a modified tab, so I think it
should be somewhat familiar to users.  And by using a "font-lock-" face,
it will be themed automatically by common third-party themes; while that
doesn't guarantee it will look good with any theme by default, it should
help.

A background color could be used as well, but I think that would be too
jarring; we already have an option to alternate the background color to
help distinguish tabs, which results in alternating shades of gray in
the default theme, which are already a bit high-contrast (subtler shades
of gray would be better, IMHO).  Having some of the tabs be, e.g. a red
background color, would be off-putting to users, IMO; I guess they might
prefer to disable the feature entirely in that case.

I also feel like a changed background color ought to be reserved for
something more urgent, like a tab that "requires attention", similar to
how desktop environments or MS-Windows highlight tabs that are trying to
get the user's attention due to an error or notification.

Having said that, it doesn't matter to me what the default face is.  If
there's a better foreground color, or a good background color, or some
other face attribute that would be a better default, let's use that.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-24 22:13       ` Adam Porter
@ 2021-09-25 19:18         ` Juri Linkov
  2021-09-26  0:14           ` Adam Porter
  0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2021-09-25 19:18 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-devel

>> But why font-lock-doc-face?  Have you tried to change tab background color?
>> I guess this would be more visually pleasing.  Or maybe not.  This needs
>> more experimentation.
>
> Because in the default theme, it results in text that's a dark red,
> which is easily distinguished against the default tab background color,
> while still being readable (IMHO).  It reminds me of other editors I've
> used that use the red color to indicate a modified tab, so I think it
> should be somewhat familiar to users.  And by using a "font-lock-" face,
> it will be themed automatically by common third-party themes; while that
> doesn't guarantee it will look good with any theme by default, it should
> help.

Ah, this explains everything - a dark red makes sense, but long ago
I customized this face to green and forgot that by default it's dark red :)

Thanks for the patch, now applied.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tab-line: New tab-line-tab-face-modified face
  2021-09-25 19:18         ` Juri Linkov
@ 2021-09-26  0:14           ` Adam Porter
  0 siblings, 0 replies; 8+ messages in thread
From: Adam Porter @ 2021-09-26  0:14 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:

>>> But why font-lock-doc-face?  Have you tried to change tab background color?
>>> I guess this would be more visually pleasing.  Or maybe not.  This needs
>>> more experimentation.
>>
>> Because in the default theme, it results in text that's a dark red,
>> which is easily distinguished against the default tab background color,
>> while still being readable (IMHO).  It reminds me of other editors I've
>> used that use the red color to indicate a modified tab, so I think it
>> should be somewhat familiar to users.  And by using a "font-lock-" face,
>> it will be themed automatically by common third-party themes; while that
>> doesn't guarantee it will look good with any theme by default, it should
>> help.
>
> Ah, this explains everything - a dark red makes sense, but long ago
> I customized this face to green and forgot that by default it's dark
> red :)

LOL, that's so easy to do.  :)

> Thanks for the patch, now applied.

Thanks.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-26  0:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24  4:57 [PATCH] tab-line: New tab-line-tab-face-modified face Adam Porter
2021-09-24  6:38 ` Juri Linkov
2021-09-24  7:09   ` Adam Porter
2021-09-24 10:29     ` Stefan Kangas
2021-09-24 15:42     ` Juri Linkov
2021-09-24 22:13       ` Adam Porter
2021-09-25 19:18         ` Juri Linkov
2021-09-26  0:14           ` Adam Porter

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).