Native display of line numbers

classic Classic list List threaded Threaded
78 messages Options
1234
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Native display of line numbers

Eli Zaretskii
I generally consider display of line numbers for each line in the
buffer un-Emacsy, something that came from the dark era when we needed
to count lines to be able to tell the then existing editors something
like "move down N lines, then DO SOMETHING".  Emacs pioneered today's
world where all this is unnecessary, and the rest is history.

However, many users want line numbers to be displayed in Emacs.  I
don't know why they want it, perhaps they were "spoiled" by other IDEs
or something.  In any case, given the popularity of the various add-on
modes which insist on displaying line numbers using all kinds of
tricks, I don't think we can ignore this tendency any longer, even if
we agree that this is a disease.  The "epidemic" has spread too far
and too wide for us to continue looking the other way.  And since
Emacs doesn't make it easy for a Lisp program to invade the holy realm
of redisplay, those modes use tricks that make Emacs slower and
frequently interfere with other packages.  They also make demands on
the display engine that make Emacs harder to develop and maintain.

So with that in mind, I came up with an implementation of a native
display of line numbers.  You can find it in the scratch/line-numbers
branch of the Emacs repository.  Compared with linum-mode,
nlinum-mode, and other similar modes, it has the following main
advantages:

  . it works significantly faster (almost twice as fast as linum-mode,
    50% faster that relative-line-numbers-mode)
  . it doesn't use the display margins
  . it works with R2L text, something the old modes never did

The main features of the line-numbering modes are all supported by
this new feature.

Please give it a try and report any bugs you find.  I'm sure there
will be quite a few bugs, given the sheer amount of display feature
which could be affected, and which I didn't have time to test.

Once the flood of serious bug reports dries out, I will look into
merging this to master.  If, miraculously, no such flood arrives, I
will merge in a couple of weeks.  When that happens, we will declare
all the other modes which do the same job deprecated.

TIA

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Stefan Monnier
> So with that in mind, I came up with an implementation of a native
> display of line numbers.

Cool!

>   . it works significantly faster (almost twice as fast as linum-mode,
>     50% faster that relative-line-numbers-mode)

Should I read this to me that the speed difference w.r.t nlinum is not
that large, or you didn't bother comparing?  (I think nlinum's
performance is pretty good (well, as long as the number of overlays doesn't
get in the way, as long as you don't try to push it towards
relative-line-number, as long as you don't enable the new
nlinum-highlight-current-line which currently has a performance bug,
...)).

>   . it works with R2L text, something the old modes never did

I didn't know there were problems with R2L text.  Worse: even now that
you tell me, I can't think of nor find a problem with it (other than the
choice of whether to display the line numbers in the left or right
margin).

I'm curious what these issues are (or were, since your code will
presumably make these limitations irrelevant).


        Stefan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Kaushal Modi
In reply to this post by Eli Zaretskii
Hi Eli,

First of all, thank you for working on this!

On Sat, Jun 17, 2017 at 11:12 AM Eli Zaretskii <[hidden email]> wrote:
I generally consider display of line numbers for each line in the
buffer un-Emacsy, something that came from the dark era when we needed
to count lines to be able to tell the then existing editors something
like "move down N lines, then DO SOMETHING".  Emacs pioneered today's
world where all this is unnecessary, and the rest is history.

While I don't use the line numbers that way, it's very useful to pinpoint a colleague directly to a piece of code, especially when not sharing the code visually; like when over a phone call: "Hey, open up the "foo" file and look at line 1534.". Nothing beats the precision of that.
 
However, many users want line numbers to be displayed in Emacs.  I
don't know why they want it, perhaps they were "spoiled" by other IDEs
or something. 

Above.
 
So with that in mind, I came up with an implementation of a native
display of line numbers.  You can find it in the scratch/line-numbers
branch of the Emacs repository. 

Thanks!
 
Compared with linum-mode,
nlinum-mode, and other similar modes, it has the following main
advantages:

  . it works significantly faster (almost twice as fast as linum-mode,
    50% faster that relative-line-numbers-mode)

How does it compare to nlinum.el in your initial testing? I will also test it out over next few days.
 
Please give it a try and report any bugs you find. 

Here's my first observation after building from that branch.

In the below image, on the left I have emacs -Q running that has the new line number feature enabled, and on the right I have older emacs instance running with nlinum.el enabled.

image.png
Can you please add support for highlighting the current line number, using a different face (See the highlighted line number by nlinum on the right hand side)?

About the code:

+(defun toggle-display-line-numbers ()
+ (interactive)
+ (if display-line-numbers
+ (setq display-line-numbers nil)
+ (setq display-line-numbers t))
+ (force-mode-line-update))

Instead of this, about about a minor mode with an intuitive name like "line-numbers-mode"? Above also has an issue, I believe.. If user has set display-line-numbers to 'relative, toggling it will always set it back to t.

How about leaving the buffer local display-line-numbers definition as it is, but replacing toggle-display-line-numbers function with a minor mode line-numbers-mode?

Thanks!
--

Kaushal Modi

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Kaushal Modi
On Sat, Jun 17, 2017, 12:52 PM Kaushal Modi <[hidden email]> wrote:

but replacing toggle-display-line-numbers function with a minor mode line-numbers-mode?

Of course the line-number-mode to toggle line numbers in just the mode line already exists. 

Can the same minor mode be reused? Then using a defcustom user can specify:

- line numbers in the margin (what would be the right word for that?), mode line or both
- line numbers in the 'margin': regular/relative
- line numbers in the 'margin': current line highlight on/off (my requested feature in the previous email)
--

Kaushal Modi

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Eli Zaretskii
In reply to this post by Kaushal Modi
> From: Kaushal Modi <[hidden email]>
> Date: Sat, 17 Jun 2017 16:52:11 +0000
>
>  . it works significantly faster (almost twice as fast as linum-mode,
>  50% faster that relative-line-numbers-mode)
>
> How does it compare to nlinum.el in your initial testing? I will also test it out over next few days.

nlinum performed so poorly in my benchmarks that I was ashamed of
publishing the data.  The benchmark entails scrolling through xdisp.c
one line at a time.  The code is at the end of this message (it was
posted by Dmitry Antipov), you can try it yourself.  The first run is
always slow because Emacs fontifies on the fly, so I timed only the
second run.

> Can you please add support for highlighting the current line number, using a different face (See the highlighted
> line number by nlinum on the right hand side)?

Is it really important?  Why? do people really have difficulty finding
the line where point/cursor is?

I could add this feature if it's deemed important, but it will slow
down redisplay to some extent, because cursor motion can no longer be
considered affecting the cursor alone.

> About the code:
>
> +(defun toggle-display-line-numbers ()
> + (interactive)
> + (if display-line-numbers
> + (setq display-line-numbers nil)
> + (setq display-line-numbers t))
> + (force-mode-line-update))
>
> Instead of this, about about a minor mode with an intuitive name like "line-numbers-mode"? Above also has an
> issue, I believe.. If user has set display-line-numbers to 'relative, toggling it will always set it back to t.

The menu bar is for simple uses, I see no reason to put all the
complexity of a defcustom on the menu bar.

> How about leaving the buffer local display-line-numbers definition as it is, but replacing
> toggle-display-line-numbers function with a minor mode line-numbers-mode?

Minor mode is probably due anyway, but that is independent of the menu
bar.

Anyway, these are simple things that can always be fixed later.  If
those are the only issues with this new feature, then I'm very lucky
(yeah, right).

Thanks for taking time to try the branch.

======================================================================

(defun scroll-up-benchmark ()
  (interactive)
  (let ((oldgc gcs-done)
        (oldtime (float-time)))
    (condition-case nil (while t (scroll-up) (redisplay))
      (error (message "GCs: %d Elapsed time: %f seconds"
                      (- gcs-done oldgc) (- (float-time) oldtime))))))

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Eli Zaretskii
In reply to this post by Kaushal Modi
> From: Kaushal Modi <[hidden email]>
> Date: Sat, 17 Jun 2017 17:20:40 +0000
>
> Of course the line-number-mode to toggle line numbers in just the mode line already exists.
>
> Can the same minor mode be reused? Then using a defcustom user can specify:

I don't think we should do that, because the other similar modes
didn't turn off line numbers in the mode line.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Eli Zaretskii
In reply to this post by Stefan Monnier
> From: Stefan Monnier <[hidden email]>
> Date: Sat, 17 Jun 2017 12:41:50 -0400
>
> > So with that in mind, I came up with an implementation of a native
> > display of line numbers.
>
> Cool!

Thanks.

> >   . it works significantly faster (almost twice as fast as linum-mode,
> >     50% faster that relative-line-numbers-mode)
>
> Should I read this to me that the speed difference w.r.t nlinum is not
> that large, or you didn't bother comparing?

See my other message: I did compare with it, of course, but the
performance was very poor.  Maybe it wasn't supposed to provide a
great performance in a file like xdisp.c.  Or maybe my benchmark is
skewed (in which case I'm sure you will provide a better one).

> >   . it works with R2L text, something the old modes never did
>
> I didn't know there were problems with R2L text.  Worse: even now that
> you tell me, I can't think of nor find a problem with it (other than the
> choice of whether to display the line numbers in the left or right
> margin).

The fact that the numbers are always displayed on the left is bad
enough; worse, the digits in the numbers are in reverse order.  E.g.,
visit TUTORIAL.he, then turn on linum-mode or nlinum-mode, and watch
the numbers closely.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Alan Mackenzie
In reply to this post by Eli Zaretskii
Hello, Eli.

On Sat, Jun 17, 2017 at 18:12:00 +0300, Eli Zaretskii wrote:
> I generally consider display of line numbers for each line in the
> buffer un-Emacsy, something that came from the dark era when we needed
> to count lines to be able to tell the then existing editors something
> like "move down N lines, then DO SOMETHING".  Emacs pioneered today's
> world where all this is unnecessary, and the rest is history.

> However, many users want line numbers to be displayed in Emacs.  I
> don't know why they want it, perhaps they were "spoiled" by other IDEs
> or something.

I'm not sure either.  One possible use is when using a build process
disjoint from Emacs which gives error and warning messages on a
terminal.  It may be easier to find the pertinent lines if the line
numbers are displayed prominently.  But this is speculation, nothing
more.

> In any case, given the popularity of the various add-on modes which
> insist on displaying line numbers using all kinds of tricks, I don't
> think we can ignore this tendency any longer, even if we agree that
> this is a disease.  The "epidemic" has spread too far and too wide for
> us to continue looking the other way.  And since Emacs doesn't make it
> easy for a Lisp program to invade the holy realm of redisplay, those
> modes use tricks that make Emacs slower and frequently interfere with
> other packages.  They also make demands on the display engine that
> make Emacs harder to develop and maintain.

Yes to all of that.

> So with that in mind, I came up with an implementation of a native
> display of line numbers.  You can find it in the scratch/line-numbers
> branch of the Emacs repository.  Compared with linum-mode,
> nlinum-mode, and other similar modes, it has the following main
> advantages:

>   . it works significantly faster (almost twice as fast as linum-mode,
>     50% faster that relative-line-numbers-mode)
>   . it doesn't use the display margins
>   . it works with R2L text, something the old modes never did

And, for me, the display engine is simply the Right Place to implement
these line numbers.

> The main features of the line-numbering modes are all supported by
> this new feature.

> Please give it a try and report any bugs you find.  I'm sure there
> will be quite a few bugs, given the sheer amount of display feature
> which could be affected, and which I didn't have time to test.

Just one or two minor irritations: it's not clear what face the line
numbers are displayed with; presumably this will become a defcustom in
the finished version.  Also, it's not clear what "relative" line numbers
are, though I dare say it would become clear if I actually tried it
(and I admit I haven't tried RTFM).  ;-)

> Once the flood of serious bug reports dries out, I will look into
> merging this to master.  If, miraculously, no such flood arrives, I
> will merge in a couple of weeks.  When that happens, we will declare
> all the other modes which do the same job deprecated.

I'm in favour of this.

> TIA

--
Alan Mackenzie (Nuremberg, Germany).

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Sébastien Le Callonnec
In reply to this post by Eli Zaretskii
Hi Eli,

On 2017-06-17 16:12:00, Eli Zaretskii wrote:
> Please give it a try and report any bugs you find.  I'm sure there
> will be quite a few bugs, given the sheer amount of display feature
> which could be affected, and which I didn't have time to test.

One issue I am noticing is that line numbers are getting displayed in
the minibuffer, when they are explicitly turned off in linum.el.  This
is particularly obvious when using ido-vertical-mode.

Thanks for tackling this – this already looks like a major improvement
over linum-mode.


Regards,
Sébastien.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Stefan Monnier
In reply to this post by Eli Zaretskii
> nlinum performed so poorly in my benchmarks that I was ashamed of
> publishing the data.  The benchmark entails scrolling through xdisp.c
> one line at a time.

Oh, yes, I think this is the case where there are too many overlays.
There's hope that the new tree-based overlays representation would solve
this problem, but I haven't actually checked.

There are also other ways to circumvent this performance problem, by
flushing the undisplayed overlays every once in a while.  I have some
code for that in nlinum.el, tho it's commented out, because it ends up
triggering re-fontification of the code later on (because currently
jit-lock can't be told to refresh nlinum without also refreshing all
other clients such as font-lock).  It'd be good to improve jit-lock so
this can be done better, but clearly this is one of those cases where
the more you progress, the more work you have to do.


        Stefan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Stefan Monnier
In reply to this post by Eli Zaretskii
>> >   . it works significantly faster (almost twice as fast as linum-mode,
>> >     50% faster that relative-line-numbers-mode)
>> Should I read this to me that the speed difference w.r.t nlinum is not
>> that large, or you didn't bother comparing?
> See my other message: I did compare with it, of course, but the
> performance was very poor.  Maybe it wasn't supposed to provide a
> great performance in a file like xdisp.c.  Or maybe my benchmark is
> skewed (in which case I'm sure you will provide a better one).

Whether or not it's representative doesn't really matter: the
performance you see with nlinum is a real problem when you bump into it.
[ IOW, I'm not here to defend nlinum ;-)  ]

>> >   . it works with R2L text, something the old modes never did
>> I didn't know there were problems with R2L text.  Worse: even now that
>> you tell me, I can't think of nor find a problem with it (other than the
>> choice of whether to display the line numbers in the left or right
>> margin).
>
> The fact that the numbers are always displayed on the left is bad
> enough; worse, the digits in the numbers are in reverse order.  E.g.,
> visit TUTORIAL.he, then turn on linum-mode or nlinum-mode, and watch
> the numbers closely.

Duh, I had tried it, but indeed skipped the "watch the numbers closely"
part.  My naive L2R background makes me think "this looks like
a rendering bug" (especially since if I insert "123" in that tutorial,
it is displayed "123" rather than "321" despite the surrounding R2L
chars, so I wonder how come the digits in the margin end up ordered
"321").


        Stefan



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Stefan Monnier
In reply to this post by Alan Mackenzie
> I'm not sure either.  One possible use is when using a build process
> disjoint from Emacs which gives error and warning messages on a
> terminal.  It may be easier to find the pertinent lines if the line
> numbers are displayed prominently.  But this is speculation, nothing
> more.

I think this is more popular nowadays also because of all those screens
that are so short yet so large that you don't really know what to do
with the horizontal real-estate (while suffering from a lack of
vertical real-estate).


        Stefan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Mathias Dahl-3
In reply to this post by Eli Zaretskii
Hi,

I have a few comments:

> I generally consider display of line numbers for each line in the
> buffer un-Emacsy, something that came from the dark era when we needed
> to count lines to be able to tell the then existing editors something
> like "move down N lines, then DO SOMETHING".

In my 20 years or so using Emacs, I can probably count on one hand the
number of times I have really wanted/needed to see line numbers
alongside the source code. And when I have had need for it the use has
mainly been what Kaushal Modi also mentions, as a quick way to refer to
one or more lines of code, immediately.

That being said, when playing around with Evil some time back, I
realized that suddenly relative line numbers (see below) were quite
useful. Perhaps this is what you refered to with the dark era. Seems
quite popular nowadays too though, even if I personally have not got the
hang of it. I prefer to "arrow down" (or up) to the line I want to, even
if it might be less optimal from a counting-keystrokes perspective.

> Emacs pioneered today's world where all this is unnecessary, and the
> rest is history.

Are you thinking now about the difference between line editors
and... whatever Emacs is (screen editor?) And, wasn't Emacs too
influenced by the limited display devices that existed back then? I
understand this is not your main point here, but you mentioned it in
your post, so... Not meaning to start an argument, by the way, I'm
mostly curious on your thinking.

> However, many users want line numbers to be displayed in Emacs.  I
> don't know why they want it, perhaps they were "spoiled" by other IDEs
> or something.

Yes, many editors have it and when I use them I seldom find the need
there either. So yes, I think that might be one reason, that people have
"got used to" (it sounds friendlier than "spoiled", I think) line
numbers from there. But, I think also the recent growth of Evil (the Vim
emulator mode, to be clear), Spacemacs and whatnot might have helped
too.

> In any case, given the popularity of the various add-on modes which
> insist on displaying line numbers using all kinds of tricks, I don't
> think we can ignore this tendency any longer, even if we agree that
> this is a disease.

A pragmatic way to look at it, I think many will welcome it.

> The "epidemic" has spread too far and too wide for us to continue
> looking the other way.

I think by now people understood that you really see no need in showing
line numbers alongside the source code... :) Let's not bash those that
do anymore.

> And since Emacs doesn't make it easy for a Lisp program to invade the
> holy realm of redisplay, those modes use tricks that make Emacs slower
> and frequently interfere with other packages.  They also make demands
> on the display engine that make Emacs harder to develop and maintain.

Again, this sounds really good, and a pragmatic way to solve things.

I will include here a comment from a later reply:

> > Can you please add support for highlighting the current line number,
> > using a different face (See the highlighted line number by nlinum on
> > the right hand side)?

> Is it really important?  Why? do people really have difficulty finding
> the line where point/cursor is?

I think it is a useful visual help/guide and probably is extra useful
when your cursor is not close to the left side of the window. When
moving up and down to a certain line, your eyes can look at the line
number in the edge that changes color, instead of trying to match where
the cursor is compared to the numbers in the edge. Of course, that exact
scenario can be done with Emacs traditional way to show line numbers on
the mode line as well. Anyway, I can easily see that it is useful to
highlight the current line number, even if I am not using it myself
much. It's a visual help, simply.

Some have touched on this subject here, but I will do it anyway:
relative line numbers seems like a useful tool to some people. For those
who haven't tried it, it works like this:

 3 ...
 2 Other line
 1 Other line
 0 This is the line I am on...
 1 Other line
 2 Other line
 3 ...

With relative line numbers it is quite easy to use a numeric argument to
move a certain number of lines up or down.

There is a risk now, when commenting on these "little things", that the focus
shifts from the primary goal you had, to show line numbers in a more efficient
and stable manner, to only discuss the small things. It is not my meaning,
and I am glad to see you are thinking to add such a feature to Emacs since
I think many users will like it, even if the reason is they are "spoiled" (now I
said it too... :)

Thanks for listening!

/Mathias


On Sat, Jun 17, 2017 at 5:12 PM, Eli Zaretskii <[hidden email]> wrote:
I generally consider display of line numbers for each line in the
buffer un-Emacsy, something that came from the dark era when we needed
to count lines to be able to tell the then existing editors something
like "move down N lines, then DO SOMETHING".  Emacs pioneered today's
world where all this is unnecessary, and the rest is history.

However, many users want line numbers to be displayed in Emacs.  I
don't know why they want it, perhaps they were "spoiled" by other IDEs
or something.  In any case, given the popularity of the various add-on
modes which insist on displaying line numbers using all kinds of
tricks, I don't think we can ignore this tendency any longer, even if
we agree that this is a disease.  The "epidemic" has spread too far
and too wide for us to continue looking the other way.  And since
Emacs doesn't make it easy for a Lisp program to invade the holy realm
of redisplay, those modes use tricks that make Emacs slower and
frequently interfere with other packages.  They also make demands on
the display engine that make Emacs harder to develop and maintain.

So with that in mind, I came up with an implementation of a native
display of line numbers.  You can find it in the scratch/line-numbers
branch of the Emacs repository.  Compared with linum-mode,
nlinum-mode, and other similar modes, it has the following main
advantages:

  . it works significantly faster (almost twice as fast as linum-mode,
    50% faster that relative-line-numbers-mode)
  . it doesn't use the display margins
  . it works with R2L text, something the old modes never did

The main features of the line-numbering modes are all supported by
this new feature.

Please give it a try and report any bugs you find.  I'm sure there
will be quite a few bugs, given the sheer amount of display feature
which could be affected, and which I didn't have time to test.

Once the flood of serious bug reports dries out, I will look into
merging this to master.  If, miraculously, no such flood arrives, I
will merge in a couple of weeks.  When that happens, we will declare
all the other modes which do the same job deprecated.

TIA


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

James Nguyen-3
> In my 20 years or so using Emacs, I can probably count on one hand the
> number of times I have really wanted/needed to see line numbers
> alongside the source code. And when I have had need for it the use has
> mainly been what Kaushal Modi also mentions, as a quick way to refer to
> one or more lines of code, immediately.

It's useful for other things too, like pair programming, "From line 22 - 33, etc...".

If you use Evil, even without Relative Numbers, it's useful to look at a line
and say Go to line 33.

Visual in memory placemarker as you scroll through code.
"Oh this is around line 900...".

Not saying there aren't other ways to achieve the goal but line numbers do
have uses..

> In any case, given the popularity of the various add-on modes which
> insist on displaying line numbers using all kinds of tricks, I don't
> think we can ignore this tendency any longer, even if we agree that
> this is a disease.

>> A pragmatic way to look at it, I think many will welcome it.

While we're on this topic, I wonder how feasible it would be to do smooth pixel
scrolling at the C layer.

> > Can you please add support for highlighting the current line number,
> > using a different face (See the highlighted line number by nlinum on
> > the right hand side)?

> Is it really important?  Why? do people really have difficulty finding
> the line where point/cursor is?

I like how nlinum highlights the current line with a different face. I think
it's a nice UI polish item. (Not everything has to be 100% for functional
                                 purposes.)

-

For Relative Numbers, a feature request would be to have the current line
represent the current line number instead of 0. I think vim 8 does that
for relative numbers.

Example:

3
2
1
456
1
2
3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Joseph Garvin
In reply to this post by Eli Zaretskii
I just signed up for the devel list to chime in: I'm a user with a real use case for line numbers, and it's not a disease ;)

I have RSI in my hands. Myself and some other emacsers use speech recognition driving emacs to code. The latency for speech recognition is not great though, and so your best bet for speed is to utter a series of commands all at once, anticipating the outcome from doing all of those actions in sequence. For this it's essential to have *relative* line numbers, so that you can say things like, "up 5, delete 3, down 2". Which is pretty much the scenario you describe, it's just there's a reason to do it still in 2017.

So I'd welcome any new code that speeds up line number calculation, although it'd be nice if it had a relative mode. What about absolute line #s? I have no idea what those heretics use it for ;)

Joe G.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Eli Zaretskii
In reply to this post by Alan Mackenzie
> Date: Sat, 17 Jun 2017 20:27:02 +0000
> Cc: [hidden email]
> From: Alan Mackenzie <[hidden email]>
>
> Just one or two minor irritations: it's not clear what face the line
> numbers are displayed with; presumably this will become a defcustom in
> the finished version.

There's already a special face for that, 'line-number', I just forgot
to mention it in NEWS.

> Also, it's not clear what "relative" line numbers are, though I dare
> say it would become clear if I actually tried it (and I admit I
> haven't tried RTFM).  ;-)

Yes, do try.  (The manual will describe this in more detail.)

> I'm in favour of this.

Thanks.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Eli Zaretskii
In reply to this post by Sébastien Le Callonnec
> From: Sébastien Le Callonnec <[hidden email]>
> Cc: Eli Zaretskii <[hidden email]>
> Date: Sat, 17 Jun 2017 21:47:50 +0100
>
> One issue I am noticing is that line numbers are getting displayed in
> the minibuffer

Only if you use setq-default to turn on the line numbers in all
buffers, I presume?  You can always turn it off explicitly in that
buffer (and any other buffer where you don't want it).

I wasn't sure no one will want numbers in the minibuffer, so I didn't
forced them off there.  I'd like to hear more opinions before deciding
on this.

Thanks.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

Kaushal Modi
In reply to this post by Eli Zaretskii
On Sat, Jun 17, 2017 at 1:41 PM Eli Zaretskii <[hidden email]> wrote:
nlinum performed so poorly in my benchmarks that I was ashamed of
publishing the data.  The benchmark entails scrolling through xdisp.c
one line at a time.  The code is at the end of this message (it was
posted by Dmitry Antipov), you can try it yourself. 

Thanks. I haven't yet tried that. I do not work in C most of the time and so may be I never noticed it. nlinum has been super smooth for me (with the current line highlight enabled too) for the major modes that I am working on. I have been using nlinum for many many years now, and the current line highlighting feature for the past year.
 
Is it really important?  Why? do people really have difficulty finding
the line where point/cursor is?

It reduces cognitive load in my experience. I need to refer to the line numbers more frequently than some; I frequently do code reviews, discuss code change with colleagues at remote locations. So with if my cursor is at the beginning of a function definition, it's really quick to glance to the left, look at the highlighted number, and tell the other people "jump to X line", instead of asking them to search for a function name, etc. I can look in the mode line too to get the line number. But this quick left glance to tell the current line num is much faster than looking for the line number in the mode line.
 
I could add this feature if it's deemed important, but it will slow
down redisplay to some extent, because cursor motion can no longer be
considered affecting the cursor alone.

Even if this feature is enabled, I believe that it would have a defcustom. If nlinum with current line highlighting is working fine, I think this should perform even better. 

The presence of packages like https://github.com/tom-tan/hlinum-mode, https://github.com/hlissner/emacs-nlinum-hl, and many people asking how to highlight the current line number on external emacs forums (like emacs.stackexchange.com or reddit.com/r/emacs) tells that many people would appreciate this feature. 

The menu bar is for simple uses, I see no reason to put all the
complexity of a defcustom on the menu bar.

The toggle-display-line-numbers is an interactive function though. So someone can unknowingly bind it to a key to toggle line numbers and get confused why their setting to show relative line numbers is getting lost. It also needs a doc-string saying that that function is only for use from the menu bar, and point the user to look at display-line-numbers var instead to do what they want. Also if that function is intended to be called only from the menu bar, should it be prefixed with "menu-bar-"? It would go against the convention used in that file, but it adds clarity.
 
Minor mode is probably due anyway, but that is independent of the menu
bar.

Anyway, these are simple things that can always be fixed later.

Understood.
 
Thanks for taking time to try the branch.

Thanks for working on this.

On Sat, Jun 17, 2017 at 1:42 PM Eli Zaretskii <[hidden email]> wrote:
> Can the same minor mode be reused? Then using a defcustom user can specify:

I don't think we should do that, because the other similar modes
didn't turn off line numbers in the mode line.

I didn't follow that. But I also see that line-number-mode is a global minor mode. For this line numbers feature, we need a mode that can be enabled just locally or globally.

We definitely need a more intuitive minor mode name for this. If this feature is a superset of linum-mode, then may be just call that.
--

Kaushal Modi

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

martin rudalics
In reply to this post by Eli Zaretskii
Thanks - a wise step.

 > Please give it a try and report any bugs you find.  I'm sure there
 > will be quite a few bugs, given the sheer amount of display feature
 > which could be affected, and which I didn't have time to test.

One problem I see is that once a window has been scrolled to the right,
it's not easy to auto-hscroll it back, at least with ‘truncate-lines’
non-nil.  For example, when with emacs -Q I here do

(progn
   (setq truncate-lines t)
   (find-file "./src/xdisp.c")
   (split-window-horizontally)
   (other-window 1)
   (goto-char (point-max))
   (end-of-line -5)
   (setq display-line-numbers t)
   (sit-for 1)
   (beginning-of-line))

the line beginnings in the window on the right won't become visible
again as long as I do just ‘left-char’.

martin


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Native display of line numbers

martin rudalics
 > (progn
 >    (setq truncate-lines t)

Silly, admittedly.  The ‘split-window-horizontally’ below does the job.

 >    (find-file "./src/xdisp.c")
 >    (split-window-horizontally)

Or setting ‘truncate-lines’ in the xdisp.c buffer.

martin


1234
Loading...