Emacs26: Quick thoughts on display-line-numbers-mode

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Emacs26: Quick thoughts on display-line-numbers-mode

Robert Weiner-2
I took a quick look at display-line-numbers-mode (nice work as always) and had a few thoughts:

1. The similar linum-mode when possible displays a subtle vertical separator between the line numbers and the left margin of the text area.  This helps to visually parse the numbers as separate from the text and helps identify where the first text character is.  It would be good to have something similar at least as an option.

Then linum-mode should be removed (maybe add an alias) so there is no confusion as to which mode should be used.

2. The mode-line popup menu that displays/hides line and col numbers in the mode=line could be expanded to toggle this mode on and off locally and globally, as well as providing options for its various display settings: relative, visual and absolute.

Bob



Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Matthew Plant-2
I agree with this, and also think there should be more customization
options.

Previously with linum I set the background of the fringe to be
different from the background of the buffer, so that the line number
column was distinct from the rest of the text buffer. It would be great
to have this option back, especially as I was excited that the
background color would finally reach the bottom of the screen when I
was reading the end of a file.

I think the two options needed for both of us would perhaps be some
sort of format string (perhaps identical to linum mode's) and then some
background option.

That being said display-line-numbers-mode effectively saved my desktop
experience. I have a 4k display so I will often have four windows of
the same file open vertically. I was recently doing this with a file
that is about 2k lines and inputting characters was causing so much
slow down that emacs was near unusable. Of course, profiling indicated
and action confirmed that linum mode was to blame.

Additionally with this change I can finally get rid of the fringe,
which makes resizing via mouse much easier.

On Thu, 2017-10-05 at 14:38 -0400, Robert Weiner wrote:

> I took a quick look at display-line-numbers-mode (nice work as
> always) and had a few thoughts:
>
> 1. The similar linum-mode when possible displays a subtle vertical
> separator between the line numbers and the left margin of the text
> area.  This helps to visually parse the numbers as separate from the
> text and helps identify where the first text character is.  It would
> be good to have something similar at least as an option.
>
> Then linum-mode should be removed (maybe add an alias) so there is no
> confusion as to which mode should be used.
>
> 2. The mode-line popup menu that displays/hides line and col numbers
> in the mode=line could be expanded to toggle this mode on and off
> locally and globally, as well as providing options for its various
> display settings: relative, visual and absolute.
>
> Bob
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Robert Weiner-2
> From: Robert Weiner <[hidden email]>
> Date: Thu, 5 Oct 2017 14:38:12 -0400
>
> 1. The similar linum-mode when possible displays a subtle vertical separator between the line numbers and
> the left margin of the text area. This helps to visually parse the numbers as separate from the text and helps
> identify where the first text character is. It would be good to have something similar at least as an option.

linum-mode displays line numbers in the left display margin.  I think
usurping the display margins for a display-related feature as popular
as line numbers is a bad idea, because it clashes with other
specialized features which want to use the margins, so I explicitly
coded the native line-number display not to do that.  Therefore, I
will object to having this new display on the display margins, even as
an option.

Separation between the numbers and the text is still kept, by means of
a white-space glyph.

> Then linum-mode should be removed (maybe add an alias) so there is no confusion as to which mode should
> be used.

I'm waiting for the pretests and the feedback we get to see if this
can be done.  It's possible that in some rare situations the new mode
will be inconvenient or unable to support.  If no such reports come
in, we will indeed retire linum-mode when Emacs 26.1 is released.

> 2. The mode-line popup menu that displays/hides line and col numbers in the mode=line could be expanded to
> toggle this mode on and off locally and globally, as well as providing options for its various display settings:
> relative, visual and absolute.

I'm not sure I agree.  The mode-line menu is for displays on the mode
line.  The display-line-numbers-mode and its variants can be turned on
or off from the menu bar's Options menu.

Thanks for your comments.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Matthew Plant-2
> From: Matthew Plant <[hidden email]>
> Date: Thu, 05 Oct 2017 11:52:01 -0700
>
> I agree with this, and also think there should be more customization
> options.

The display-line-numbers feature has no less than 7 customization
options and 3 sub-modes, most of them documented in the manual.  What
else is missing?

> Previously with linum I set the background of the fringe to be
> different from the background of the buffer, so that the line number
> column was distinct from the rest of the text buffer. It would be great
> to have this option back

This is already supported via 2 faces: the line-number face and
line-number-current-line face.  Or do I misunderstand what you want?

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Robert Weiner-2
In reply to this post by Eli Zaretskii
On Thu, Oct 5, 2017 at 3:02 PM, Eli Zaretskii <[hidden email]> wrote:

linum-mode displays line numbers in the left display margin.  I think
usurping the display margins for a display-related feature as popular
as line numbers is a bad idea, because it clashes with other
specialized features which want to use the margins, so I explicitly
coded the native line-number display not to do that.  Therefore, I
will object to having this new display on the display margins, even as
an option.

​Ok.
​​

​​
Separation between the numbers and the text is still kept, by means of
​​
a white-space glyph.

​So could you add a customization option for this glyph that would provide some visual separation, e.g. a hairline or something similar to the visual linum-mode provides?

​​

​​
> Then linum-mode should be removed (maybe add an alias) so there is no confusion as to which mode should
​​
> be used.
​​

​​
I'm waiting for the pretests and the feedback we get to see if this
​​
can be done.  It's possible that in some rare situations the new mode
​​
will be inconvenient or unable to support.  If no such reports come
​​
in, we will indeed retire linum-mode when Emacs 26.1 is released.

​Ok.​

​​
> 2. The mode-line popup menu that displays/hides line and col numbers in the mode=line could be expanded to
​​
> toggle this mode on and off locally and globally, as well as providing options for its various display settings:
​​
> relative, visual and absolute.
​​

​​
I'm not sure I agree.  The mode-line menu is for displays on the mode
​​
line.  The display-line-numbers-mode and its variants can be turned on
​​
or off from the menu bar's Options menu.
I see your point but do think in practice a lot of people would look to the mode-line menu if they could.  Also, having all the options in one place would let people decide which to use at any given point without hunting around.  I know I look at mode-lines a lot more than the menubar.  It would also force a cleanup of the menu item naming so that it was obvious where each option will display its numbers.

​Bob

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Eli Zaretskii
> From: Matthew Plant <[hidden email]>
> Date: Thu, 05 Oct 2017 12:35:29 -0700
>
> My apologies, I did not notice that line-number face existed because it
> is not part of the display line numbers group. This does exactly what I
> want.
>
> That being said, shouldn't this face be part of the group display-line-
> number? Faces for compilation errors are part of the the compilation
> group.

My reasoning was that this is one of the basic faces we provide, so
it's in the basic faces group.

> Being able to specify which side the line numbers appear I imagine
> would be useful for editing right to left languages.

When the paragraph direction is right-to-left, the numbers
automatically appear on the right.  You should be able to see that if
you visit TUTORIAL.he with display-line-numbers-mode turned on.

> That being said I can't find one editor that supports this feature

Well, Emacs does ;-)

> You said in a separate reply that separation between the numbers and
> the text is kept with a white-space glyph. Why not just let this be a
> buffer or mode local string specified by the user?

There's a technical problem with doing that, which I couldn't solve.
It would also slow down redisplay, while performance was high on my
priority list when working on this feature.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Robert Weiner-2
> From: Robert Weiner <[hidden email]>
> Date: Thu, 5 Oct 2017 15:44:54 -0400
> Cc: emacs-devel <[hidden email]>
>
>  ​​Separation between the numbers and the text is still kept, by means of
>  ​​a white-space glyph.
>
> ​So could you add a customization option for this glyph that would provide some visual separation, e.g. a
> hairline or something similar to the visual linum-mode provides?

There's a technical problem with doing that, for which I didn't have a
solution at the time and still don't.  Such an option would also slow
redisplay, albeit in minor ways.

>  ​​> 2. The mode-line popup menu that displays/hides line and col numbers in the mode=line could be
>  expanded to
>  ​​> toggle this mode on and off locally and globally, as well as providing options for its various display
>  settings:
>  ​​> relative, visual and absolute.
>  ​​
>  ​​I'm not sure I agree. The mode-line menu is for displays on the mode
>  ​​line. The display-line-numbers-mode and its variants can be turned on
>  ​​or off from the menu bar's Options menu.
>
> ​I see your point but do think in practice a lot of people would look to the mode-line menu if they could. Also,
> having all the options in one place would let people decide which to use at any given point without hunting
> around. I know I look at mode-lines a lot more than the menubar.

Well, currently the mode line offers customization only of the stuff
that is displayed on the mode line, so I'm not sure why people would
look there or something else.

> It would also force a cleanup of the menu item
> naming so that it was obvious where each option will display its numbers.

Not sure I understand: the Options menu has Hide/Show sub-menu, which
is where we put all the toggle-type options.  Line-number display is
one of them.  So it looks like the current arrangement is consistent
with how we provide similar customizations.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Matthew Plant-2
In reply to this post by Eli Zaretskii
On Thu, 2017-10-05 at 22:50 +0300, Eli Zaretskii wrote:

> > From: Matthew Plant <[hidden email]>
> > Date: Thu, 05 Oct 2017 12:35:29 -0700
> >
> > My apologies, I did not notice that line-number face existed
> > because it
> > is not part of the display line numbers group. This does exactly
> > what I
> > want.
> >
> > That being said, shouldn't this face be part of the group display-
> > line-
> > number? Faces for compilation errors are part of the the
> > compilation
> > group.
>
> My reasoning was that this is one of the basic faces we provide, so
> it's in the basic faces group.
>
Hmm... Ok.

> > Being able to specify which side the line numbers appear I imagine
> > would be useful for editing right to left languages.
>
> When the paragraph direction is right-to-left, the numbers
> automatically appear on the right.  You should be able to see that if
> you visit TUTORIAL.he with display-line-numbers-mode turned on.
>
> > That being said I can't find one editor that supports this feature
>
> Well, Emacs does ;-)
>

I was silently wondering if this was the case. Oops, my bad.

> > You said in a separate reply that separation between the numbers
> > and
> > the text is kept with a white-space glyph. Why not just let this be
> > a
> > buffer or mode local string specified by the user?
>
> There's a technical problem with doing that, which I couldn't solve.
> It would also slow down redisplay, while performance was high on my
> priority list when working on this feature.

If you can elaborate on the technical problem I can give it a look.
If the glyph is limited to one character and is properly cached I don't
see why this would be a specificaly worrisome performance hit. I can
see it being an issue if the glyph is changed a lot, but I don't think
this is a common use case.

I'm making some assumptions about the display code, I'll take a look at
the implementation.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Robert Weiner-2
In reply to this post by Eli Zaretskii
On Thu, Oct 5, 2017 at 3:58 PM, Eli Zaretskii <[hidden email]> wrote:

Not sure I understand: the Options menu has Hide/Show sub-menu, which
is where we put all the toggle-type options.  Line-number display is
one of them.  So it looks like the current arrangement is consistent
with how we provide similar customizations.

​I see.  The menu items on that menu are exactly what I would put on the modeline menu for quick access, though I would make it a one-level menu.  It takes a lot of time to go to Options, visually scan down the menu, find Hide/Show, etc.  Versus a quick click on the modeline and you are setting this.  Then either place people go would be wholly consistent.

Bob

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Alex-2
In reply to this post by Eli Zaretskii
Eli Zaretskii <[hidden email]> writes:

>> That being said, shouldn't this face be part of the group display-line-
>> number? Faces for compilation errors are part of the the compilation
>> group.
>
> My reasoning was that this is one of the basic faces we provide, so
> it's in the basic faces group.

It appears that a face can be added to multiple groups. Perhaps this
should be done for the line-number* faces?

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Matthew Plant-2
In reply to this post by Eli Zaretskii
On Thu, 2017-10-05 at 22:58 +0300, Eli Zaretskii wrote:

> > From: Robert Weiner <[hidden email]>
> > Date: Thu, 5 Oct 2017 15:44:54 -0400
> > Cc: emacs-devel <[hidden email]>
> >
> >  Separation between the numbers and the text is still kept, by
> > means of
> >  a white-space glyph.
> >
> > So could you add a customization option for this glyph that would
> > provide some visual separation, e.g. a
> > hairline or something similar to the visual linum-mode provides?
>
> There's a technical problem with doing that, for which I didn't have
> a
> solution at the time and still don't.  Such an option would also slow
> redisplay, albeit in minor ways.
>
For now, you can go to src/xdisp.c:20996 and change the line:
    strcat (lnum_buf, " ");
to  
   strcat (lnum_buf, "|");

This change works pretty well, although it's not as nice as having a
complete line.

Although I think I like the pipe character better than the space.

> >  > 2. The mode-line popup menu that displays/hides line and col
> > numbers in the mode=line could be
> >  expanded to
> >  > toggle this mode on and off locally and globally, as well as
> > providing options for its various display
> >  settings:
> >  > relative, visual and absolute.
> >  
> >  I'm not sure I agree. The mode-line menu is for displays on the
> > mode
> >  line. The display-line-numbers-mode and its variants can be
> > turned on
> >  or off from the menu bar's Options menu.
> >
> > I see your point but do think in practice a lot of people would
> > look to the mode-line menu if they could. Also,
> > having all the options in one place would let people decide which
> > to use at any given point without hunting
> > around. I know I look at mode-lines a lot more than the menubar.
>
> Well, currently the mode line offers customization only of the stuff
> that is displayed on the mode line, so I'm not sure why people would
> look there or something else.
>
> > It would also force a cleanup of the menu item
> > naming so that it was obvious where each option will display its
> > numbers.
>
> Not sure I understand: the Options menu has Hide/Show sub-menu, which
> is where we put all the toggle-type options.  Line-number display is
> one of them.  So it looks like the current arrangement is consistent
> with how we provide similar customizations.
>

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Alex-2
> From: Alex <[hidden email]>
> Cc: Matthew Plant <[hidden email]>,  [hidden email]
> Date: Thu, 05 Oct 2017 17:24:15 -0600
>
> Eli Zaretskii <[hidden email]> writes:
>
> >> That being said, shouldn't this face be part of the group display-line-
> >> number? Faces for compilation errors are part of the the compilation
> >> group.
> >
> > My reasoning was that this is one of the basic faces we provide, so
> > it's in the basic faces group.
>
> It appears that a face can be added to multiple groups.

Which other faces are in more than one group?

> Perhaps this should be done for the line-number* faces?

If this is established practice, no objections here.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
In reply to this post by Matthew Plant-2
> From: Matthew Plant <[hidden email]>
> Cc: [hidden email]
> Date: Thu, 05 Oct 2017 20:09:39 -0700
>
> > There's a technical problem with doing that, for which I didn't have
> > a
> > solution at the time and still don't.  Such an option would also slow
> > redisplay, albeit in minor ways.
> >
> For now, you can go to src/xdisp.c:20996 and change the line:
>     strcat (lnum_buf, " ");
> to  
>    strcat (lnum_buf, "|");

The problem with this is that in R2L paragraphs the glyph should
_precede_ the number, i.e. be to the left of the number.  And when the
number is generated for the first line to be redrawn, the paragraph
direction was not yet computed.  This is the technical problem to
which I alluded.  Until I find a way to solve it, such solutions
cannot be accepted, sorry.

> Although I think I like the pipe character better than the space.

That definitely depends on the font you are using.  Some fonts have an
extremely ugly pipe glyphs.  So this will have to be another
customization option, not just a hard-coded character.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Matthew Plant-2
Yes, I should have read the comment literally right above the line I suggested changing.
I didn’t mean to offer that snippet as a solution, just as a suggestion for anyone compiling themselves. I would be more formal otherwise.
If I understand the problem correctly, since orientation depends on paragraph, does that mean line numbers could be on different sides in the same window?
I think I have an approach for fixing this

> On Oct 6, 2017, at 12:26 AM, Eli Zaretskii <[hidden email]> wrote:
>
>> From: Matthew Plant <[hidden email]>
>> Cc: [hidden email]
>> Date: Thu, 05 Oct 2017 20:09:39 -0700
>>
>>> There's a technical problem with doing that, for which I didn't have
>>> a
>>> solution at the time and still don't.  Such an option would also slow
>>> redisplay, albeit in minor ways.
>>>
>> For now, you can go to src/xdisp.c:20996 and change the line:
>>    strcat (lnum_buf, " ");
>> to  
>>   strcat (lnum_buf, "|");
>
> The problem with this is that in R2L paragraphs the glyph should
> _precede_ the number, i.e. be to the left of the number.  And when the
> number is generated for the first line to be redrawn, the paragraph
> direction was not yet computed.  This is the technical problem to
> which I alluded.  Until I find a way to solve it, such solutions
> cannot be accepted, sorry.
>
>> Although I think I like the pipe character better than the space.
>
> That definitely depends on the font you are using.  Some fonts have an
> extremely ugly pipe glyphs.  So this will have to be another
> customization option, not just a hard-coded character.


Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
> From: Matthew Plant <[hidden email]>
> Date: Fri, 6 Oct 2017 00:50:10 -0700
> Cc: [hidden email],
>  [hidden email]
>
> If I understand the problem correctly, since orientation depends on paragraph, does that mean line numbers could be on different sides in the same window?

Yes.  You can see that in action if you visit TUTORIAL.he with
display-line-numbers-mode turned on.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Stefan Monnier
>> If I understand the problem correctly, since orientation depends on
>> paragraph, does that mean line numbers could be on different sides in the
>> same window?
> Yes.  You can see that in action if you visit TUTORIAL.he with
> display-line-numbers-mode turned on.

Oh, wow, I hadn't realized that.  Is that the generally expected behavior?

As a naive user who can't read any R2L scripts, I find this very
unexpected.  I'd have expected/wanted instead the line numbers to always
be on the same side for a given window (tho I admit that I'm not sure
how to turn this rule into an implementable behavior, except maybe by
letting the user decide globally whether line numbers should be on the
left or the right).

But again, I'm just a very naive user who's never bothered by the
current behavior because he never faces such situations anyway.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
> From: Stefan Monnier <[hidden email]>
> Date: Fri, 06 Oct 2017 08:37:37 -0400
>
> >> If I understand the problem correctly, since orientation depends on
> >> paragraph, does that mean line numbers could be on different sides in the
> >> same window?
> > Yes.  You can see that in action if you visit TUTORIAL.he with
> > display-line-numbers-mode turned on.
>
> Oh, wow, I hadn't realized that.  Is that the generally expected behavior?

I don't know.  It doesn't strike me as blatantly wrong, to give you
just one data point.  I guess we will have to hear more from users.
In general, buffers with changing paragraph direction are quite rare,
btw.

> As a naive user who can't read any R2L scripts, I find this very
> unexpected.  I'd have expected/wanted instead the line numbers to always
> be on the same side for a given window (tho I admit that I'm not sure
> how to turn this rule into an implementable behavior, except maybe by
> letting the user decide globally whether line numbers should be on the
> left or the right).

Currently, the only way of doing that is set bidi-paragraph-direction
to a non-nil value.

> But again, I'm just a very naive user who's never bothered by the
> current behavior because he never faces such situations anyway.

Thanks, noted.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

John Wiegley-6
EZ> I don't know. It doesn't strike me as blatantly wrong, to give you just
EZ> one data point. I guess we will have to hear more from users. In general,
EZ> buffers with changing paragraph direction are quite rare, btw.

As someone who edits R2L buffers, I'd prefer line numbers always being on one
side of the buffer or the other -- hopefully with an easy way to fix the side,
or toggle it depending on what I'm doing. English text with R2L in it is
usually a different scenario than R2L with some English in it.

--
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

Eli Zaretskii
> From: "John Wiegley" <[hidden email]>
> Cc: Stefan Monnier <[hidden email]>,  [hidden email]
> Date: Fri, 06 Oct 2017 09:25:09 -0400
>
> EZ> I don't know. It doesn't strike me as blatantly wrong, to give you just
> EZ> one data point. I guess we will have to hear more from users. In general,
> EZ> buffers with changing paragraph direction are quite rare, btw.
>
> As someone who edits R2L buffers, I'd prefer line numbers always being on one
> side of the buffer or the other -- hopefully with an easy way to fix the side,
> or toggle it depending on what I'm doing. English text with R2L in it is
> usually a different scenario than R2L with some English in it.

If you have R2L text with some English in it, you can easily arrange
for paragraph direction always being R2L.

But your opinion is noted, thanks.  I still think we need much more
feedback before we decide to change the current implementation,
especially since it's not a trivial change.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs26: Quick thoughts on display-line-numbers-mode

John Wiegley-6
>>>>> Eli Zaretskii <[hidden email]> writes:

> But your opinion is noted, thanks. I still think we need much more feedback
> before we decide to change the current implementation, especially since it's
> not a trivial change.

Agreed.

--
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

12