Emacs for some reason did not vacate equal spaces for each line number, So the lines were starting at different places which made it harder to keep track of alignment. It wasn't just the relative mode which had this problem, even the absolute mode does. Linum mode is quite heavy when compared to display-line-numbers.el.
1 Answer
This is what fixed my issue. All this is doing is, when the buffer is being setup for reading it would read the last line number and add the width of the number as the display-line-numbers-width.
(defun display-line-numbers-equalize ()
"Equalize The width"
(setq display-line-numbers-width (length (number-to-string (line-number-at-pos (point-max))))))
(add-hook 'find-file-hook 'display-line-numbers-equalize)
-
1Leaving
display-line-numbers-width
to the defaultnil
value should do the same thing. If it does not, you should report it.– NickDJan 28, 2020 at 16:27 -
@NickD So the help menu shows this. The default value of nil means compute the space dynamically. I am not sure what dynamic means in this context, per buffer or per line? Jan 29, 2020 at 14:18
-
2Actually, I was wrong: it does not do the same thing. "Dynamic" means that it leaves enough space for the longest visible line number in the buffer. When you scroll down and you get to longer line numbers, the display will shift to accommodate them.– NickDJan 29, 2020 at 14:32
display-line-numbers-mode
you should report it viaM-x report-emacs-bug RET
.