I like that Emacs 26's line numbers are fast, but they seem to have a problem. If you open an empty buffer, there is an empty area which is reserved for line numbers:

enter image description here

Once you add some text onto that line, the empty area actually fills up with a line number:

enter image description here

Unfortunately, when that area is empty it's pretty ugly. It's a bit confusing to open an empty buffer and see the cursor moved off to the right. It can make one think that they accidentally tabbed over there somehow.

I've tried fiddling around with display-line-numbers-width and display-line-numbers-width-start, but they seem to do no good to relieve this issue. What can I do so that this empty area is shrunken when the line is empty? Or at least, can I make a line number show up on that line even when it is empty? Some visual distinction would be nice at the very least, so that I know that I haven't mistakenly tabbed over.

  • This isn't specific to empty buffers, though. If the last 'line' of the buffer is empty, it isn't numbered. An empty buffer is just a special case of that scenario, but the behaviour is consistent.
    – phils
    Jul 6, 2018 at 3:45
  • In response to one of my bug reports or Emacs Devel mailing list inquiries about a year ago, the author of built-in native line numbering (Eli Z.) explained to me at the outset of this new (now somewhat old) feature that the absence of a line number for an empty line (without anything such as a space or a hard return) is "a feature". As far as I am aware, there is no customizable option to make the line-number-display-width have a value of 0 when the buffer is empty.
    – lawlist
    Jul 6, 2018 at 3:47
  • @phils Ok, I see what you're saying. Is there some way around this problem in general?
    – GDP2
    Jul 6, 2018 at 9:41
  • as a work-around, you could try putting some text in the buffer
    – Tyler
    Jul 7, 2018 at 2:29

1 Answer 1


GNU bug report logs - #28247; Display native line number on last line of buffer (when empty line): https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28247

Q:  "Emacs does not display a native line number on the last line of the buffer unless there is something there in addition to the cursor. What would be a good approach to modifying the C code to draw a line number at the end of the buffer when it is an empty line. disable_line_numbers_overlay_at_eob in should_produce_line_number seems like the cause of this behavior that I wish to change."

A:  "This is a feature:  'the last line' is not actually a line, there's no character there."

As far as I am aware, there is no customizable option to make the line-number-display-width have a value of 0 when the buffer is empty.

  • Well, this is too bad. It sounds like you're saying there's just no solution to the problem... I can understand if that's the case, but I really hope there's some way around the issue. Stopping at "it's not a bug; it's a feature!" is not satisfactory in this case.
    – GDP2
    Jul 6, 2018 at 9:40
  • @GDP2 so you should get involved in that bug report, and make your case for a user option to control that.
    – phils
    Jul 6, 2018 at 9:52
  • @lawlist Apparently, they fixed this in Emacs 26.2 by highlighting the entire area reserved for line numbers with the line-number face (except for the current line which is highlighted with the line-number-current-line face). You can see the details in the ChangeLog here. If you update your answer to mention this fix, I'll go ahead and accept it.
    – GDP2
    Jun 4, 2019 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.