Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Emacs pretest: highlight line number in display-line-numbers-mode?

524 views
Skip to first unread message

Sivaram Neelakantan

unread,
Oct 19, 2017, 11:19:04 AM10/19/17
to

The new display-line-numbers-mode in the Emacs pretest works nicely
and seems faster than linum. Thanks Eli.

Is there a way to highlight the current line number on the fringe in a
different face where the cursor is? Like hl-line-mode except just the
line number is bold or in a different colour?

sivaram
--

Robert Pluim

unread,
Oct 19, 2017, 11:37:42 AM10/19/17
to Sivaram Neelakantan, help-gn...@gnu.org
Face: line-number-current-line (sample) (customize this face)

Documentation:
Face for displaying the current line number.

Robert

Drew Adams

unread,
Oct 19, 2017, 1:18:38 PM10/19/17
to Robert Pluim, Sivaram Neelakantan, help-gn...@gnu.org
> > Is there a way to highlight the current line number on the fringe in a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > different face where the cursor is? Like hl-line-mode except just the
> > line number is bold or in a different colour?
>
> Face: line-number-current-line (sample) (customize this face)

(The line number is not actually in the fringe, BTW.)

Not that I really care, for myself, as I don't use line-number
display, but this is yet another case of the misguided (IMHO)
use of a face that does not appear differently from others by
default.

If the default value of face `line-number-current-line'
looked different from that of face `line-number' then
there would be little need to pose the question of whether
you can highlight the current line number differently.
The only question then might be how to do so.

(I have never understood why Emacs sometimes chooses to
provide a face and yet "hide" it from users by default.
That seems very wrong.)

An additional problem (is there a good answer here?) is that
this face is used in a place where you cannot put the cursor
and use `C-u C-x =' to find out what the face is.

To find the face used, I use `list-faces-display' and look
for either a face name that is a likely candidate
(`line-number' is pretty obvious, in this case) or a face
appearance that matches what I see.

Maybe we could have a mouse command (e.g. bound to some
prefix key plus a mouse click) that would let you get the
same info that `C-u C-x =' provides by clicking in (at
least some) places where there is no text?

But it doesn't seem like a click on a displayed line number
registers a particular event that is different from clicking
on nearby buffer text (unlike the case for clicking in the
fringe, for instance), so perhaps this is not feasible for
at least some click spots. Still, it would presumably be
possible for some such non-text spots, such as the fringe.

Eli Zaretskii

unread,
Oct 19, 2017, 4:10:09 PM10/19/17
to help-gn...@gnu.org
> Date: Thu, 19 Oct 2017 10:18:25 -0700 (PDT)
> From: Drew Adams <drew....@oracle.com>
> Cc: help-gn...@gnu.org
>
> If the default value of face `line-number-current-line'
> looked different from that of face `line-number' then
> there would be little need to pose the question of whether
> you can highlight the current line number differently.

This face is by default the same as line-number because of 2 reasons:

. linum-mode did the same
. using a different face makes redisplay slightly slower (because it
disallows some redisplay optimizations)

> To find the face used, I use `list-faces-display' and look
> for either a face name that is a likely candidate
> (`line-number' is pretty obvious, in this case) or a face
> appearance that matches what I see.

There are other places where this doesn't work, e.g. on the mode line.

Drew Adams

unread,
Oct 19, 2017, 4:43:23 PM10/19/17
to Eli Zaretskii, help-gn...@gnu.org
> This face is by default the same as line-number because of 2 reasons:
>
> . linum-mode did the same

...chasing that rabbit: Why did `linum-mode' do that?

Two wrongs don't necessarily make a right.

> . using a different face makes redisplay slightly slower
> (because it disallows some redisplay optimizations)

Would those optimizations still be available if a
user chose the same face for both (but the faces
were different by default)?

If so, I'd suggest making the faces different by
default. And if the performance difference is
important then perhaps mention it in the doc,
so users who want that optimization at the cost
of not highlighting the current line number can
get it. IOW, opt-in for the loss of a difference.

> > To find the face used, I use `list-faces-display' and look
> > for either a face name that is a likely candidate
> > (`line-number' is pretty obvious, in this case) or a face
> > appearance that matches what I see.
>
> There are other places where this doesn't work, e.g. on the
> mode line.

What do you mean by "this"? Using `list-faces-display'
or the fact that you can't use `C-u C-x =' to learn
the face?

You gave that reply after my mention of the former.
Aren't all of the faces used in the mode line shown in
`list-faces-display'? At least all faces with "mode-line"
in their name are listed there.

There are certainly several places where you cannot use
`C-u C-x =' to see what the face is. (In particular,
places where there is no cursor/buffer position.)

Eli Zaretskii

unread,
Oct 20, 2017, 2:34:59 AM10/20/17
to help-gn...@gnu.org
> Date: Thu, 19 Oct 2017 13:43:06 -0700 (PDT)
> From: Drew Adams <drew....@oracle.com>
>
> > This face is by default the same as line-number because of 2 reasons:
> >
> > . linum-mode did the same
>
> ...chasing that rabbit: Why did `linum-mode' do that?

I don't know, but too many differences from a previous feature tend to
annoy people IME.

> > . using a different face makes redisplay slightly slower
> > (because it disallows some redisplay optimizations)
>
> Would those optimizations still be available if a
> user chose the same face for both (but the faces
> were different by default)?
>
> If so, I'd suggest making the faces different by
> default.

They are already different by default. They just have the same
attributes.

> IOW, opt-in for the loss of a difference.

That's already so.

> > > To find the face used, I use `list-faces-display' and look
> > > for either a face name that is a likely candidate
> > > (`line-number' is pretty obvious, in this case) or a face
> > > appearance that matches what I see.
> >
> > There are other places where this doesn't work, e.g. on the
> > mode line.
>
> What do you mean by "this"? Using `list-faces-display'
> or the fact that you can't use `C-u C-x =' to learn
> the face?

The latter.

> You gave that reply after my mention of the former.
> Aren't all of the faces used in the mode line shown in
> `list-faces-display'?

They are, but so are the line-number faces.

Robert Pluim

unread,
Oct 20, 2017, 9:49:22 AM10/20/17
to Eli Zaretskii, help-gn...@gnu.org
Eli Zaretskii <el...@gnu.org> writes:

>> Date: Thu, 19 Oct 2017 13:43:06 -0700 (PDT)
>> From: Drew Adams <drew....@oracle.com>
>>
>> > This face is by default the same as line-number because of 2 reasons:
>> >
>> > . linum-mode did the same
>>
>> ...chasing that rabbit: Why did `linum-mode' do that?
>
> I don't know, but too many differences from a previous feature tend to
> annoy people IME.

nlinum-mode has an option to highlight the current line, disabled by
default (I never turned it on because I didn't know it existed, but I
do have it turned on for the builtin support)

I'd vote for having the current line face have a background colour
set. Calculating line numbers is going to slow things down anyway, so
a little less speed doesn't matter to me. Something like:

diff --git i/lisp/faces.el w/lisp/faces.el
index a5f1d1dd32..a2bb2cd1b3 100644
--- i/lisp/faces.el
+++ w/lisp/faces.el
@@ -2487,7 +2487,12 @@ line-number
:group 'display-line-numbers)

(defface line-number-current-line
- '((t :inherit line-number))
+ '((((class color) (background light))
+ :inherit line-number :background "grey95")
+ (((class color) (background dark))
+ :inherit line-number :background "grey10")
+ (t
+ :inherit line-number :background "gray"))
"Face for displaying the current line number.
This face is used when `display-line-numbers' is non-nil.

Robert

Eli Zaretskii

unread,
Oct 20, 2017, 10:49:43 AM10/20/17
to help-gn...@gnu.org
> From: Robert Pluim <rpl...@gmail.com>
> Cc: help-gn...@gnu.org
> Date: Fri, 20 Oct 2017 15:49:07 +0200
>
> nlinum-mode has an option to highlight the current line, disabled by
> default

So does display-line-numbers-mode, by way of the
line-number-current-line face. Or am I missing something?

> I'd vote for having the current line face have a background colour
> set.

By default? Why do you need it by default? What's wrong with lettng
users customize that as they see fit?

> Calculating line numbers is going to slow things down anyway

It doesn't. I measured it. And there's no reason why it should slow
down, because the line numbers are computed on the fly, as the lines
are laid out for display.

Drew Adams

unread,
Oct 20, 2017, 11:18:16 AM10/20/17
to Eli Zaretskii, help-gn...@gnu.org
> > I'd vote for having the current line face have a background colour
> > set.
>
> By default? Why do you need it by default? What's wrong
> with lettng users customize that as they see fit?

We've already answered that: It is not obvious that they
have that possibility. They can't see that there are
two different faces involved, with the default behavior.

If you make a difference invisible, you are not exactly
helping users to be aware of it.

The second reason is that showing which line is current
is helpful. Anyone who is annoyed by seeing that can
opt out, customizing the current-line face to look the
same as the other-line face.

Drew Adams

unread,
Oct 20, 2017, 11:18:28 AM10/20/17
to Eli Zaretskii, help-gn...@gnu.org
> > > . using a different face makes redisplay slightly slower
> > > (because it disallows some redisplay optimizations)
> >
> > Would those optimizations still be available if a
> > user chose the same face for both (but the faces
> > were different by default)?

?

I guess you are confirming that the optimizations you
spoke of are a red herring here: they would anyway be
available whenever someone customizes the current-line
face to have the same appearance as the other-lines face.
Or do you want to correct this guess?

> > If so, I'd suggest making the faces different by
> > default.
>
> They are already different by default. They just have
> the same attributes.

I think you understood perfectly well that I was
referring to a difference of _appearance_, not the fact
that there are two different face objects. There are
two faces, but they have the same appearance by default.
That's the misdesign.

Please consider giving them a different appearance by
default. That will help users see which is the current
line, and it will help users know that there are two
different faces, which they can customize.

If you think it is important, add a doc mention that if
the faces have the same attribute values then display
performance can be better.

> > IOW, opt-in for the loss of a difference.
>
> That's already so.

No. If the appearance is the same by default then
you have to opt out of that default behavior to see
a difference. Lack of a difference in appearance
is not opt-in currently; it is the default behavior.

Eli Zaretskii

unread,
Oct 20, 2017, 11:43:12 AM10/20/17
to help-gn...@gnu.org
> Date: Fri, 20 Oct 2017 08:18:02 -0700 (PDT)
> From: Drew Adams <drew....@oracle.com>
>
> > > I'd vote for having the current line face have a background colour
> > > set.
> >
> > By default? Why do you need it by default? What's wrong
> > with lettng users customize that as they see fit?
>
> We've already answered that:

Who are 'we"? I was answering to Robert.

> It is not obvious that they have that possibility. They can't see
> that there are two different faces involved, with the default
> behavior.

Yes, you already said that, it wasn't convincing the first time. The
documentation exists for a reason.

> The second reason is that showing which line is current
> is helpful. Anyone who is annoyed by seeing that can
> opt out, customizing the current-line face to look the
> same as the other-line face.

There are several features that show the current line, all of them
optional. I see no reason to make that on by default now, and in any
case this is a separate issue. IOW, if you are lobbying for making
the line-number-current face be distinct by default for this reason,
you will have first to convince that making the current line stand out
by default is a good idea. (And the place to make that argument is
not here.)

Eli Zaretskii

unread,
Oct 20, 2017, 11:52:26 AM10/20/17
to help-gn...@gnu.org
> Date: Fri, 20 Oct 2017 08:18:07 -0700 (PDT)
> From: Drew Adams <drew....@oracle.com>
>
> > > > . using a different face makes redisplay slightly slower
> > > > (because it disallows some redisplay optimizations)
> > >
> > > Would those optimizations still be available if a
> > > user chose the same face for both (but the faces
> > > were different by default)?
>
> ?
>
> I guess you are confirming that the optimizations you
> spoke of are a red herring here:

It's not a red herring, you can see that in the code.

> they would anyway be available whenever someone customizes the
> current-line face to have the same appearance as the other-lines
> face.

The current-line face has the same appearance by default, making those
optimizations possible. When the appearance is different, the
optimizations are disabled. I hope what I say is now perfectly clear.

It is not clear to me what change you are lobbying for, except for
changing the defaults, which is something that was already asked and
answered.

> There are two faces, but they have the same appearance by default.
> That's the misdesign.

And as I already said, this "misdesign" has a good reason, so the
"mis" part is uncalled for. You might disagree with my design, but
please don't use denigrating terms just because you do.

In any case, we already have several other faces that by default look
the same, so this is not an odd case.

> Please consider giving them a different appearance by
> default.

I already explained why I didn't think this was a good idea. What is
the purpose of repeating the same request?

0 new messages