3

With linum-mode, you could change how the line numbers appears by customizing linum-format.

line-number-mode appears to have replaced linum-mode, and indeed it is better (for one thing, it correctly right aligns the line numbers). However, I can't find any formatting options.

What I would like to do is

  • Remove the empty space before the line number
  • Replace the space after the line number with .

(Note that I use terminal emacs)

I used to do this by setting linum-format to %d⎢.

If there aren't any formatting options, can I at least remove the left vertical column and change the character used, or if that's not possible, set a face for the right one?

asmeurer
  • 1,552
  • 12
  • 30

1 Answers1

4

In a closely related question How to change line-number gutter width using display-line-numbers mode? , I wrote up an answer essentially stating that there is no user option to configure the left/right padding for the built-in line numbers. This is written into the C internals of Emacs in the file xdisp.c. The left padding of the built-in line numbers is controlled by the line of code that reads pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display); (i.e., the + 1 creates the left space); and, the right padding is controlled by the line of code that reads strcat (lnum_buf, " ");

I felt that the idea of having a user option was worth pursuing and I raised this issue on the Emacs Devel mailing list, including, but not limited to some proof-concept screenshots. The screenshots that I generated appear to be exactly what the O.P. is proposing in the question of this current thread:

https://lists.gnu.org/archive/html/emacs-devel/2019-08/msg00418.html

The lead maintainer/developer (Eli Z.), who created the built-in line numbers of xdisp.c, opted not to pursue this idea for the reasons stated in the thread:

https://lists.gnu.org/archive/html/emacs-devel/2019-08/msg00426.html

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • Thanks, I figured as much. Maybe one could somehow change the right space character to something else by finding and editing the memory. I don't know how to post in that thread, but I would note that the extra space is significant in terminal emacs. It can make the difference between a horizontally split window fitting 80 characters of text or not, even with the terminal full screen, (I tend to keep my font size larger so I can read things comfortably). Of course, being in a document with over 1000 lines can also make that difference, but I consider that to be an acceptable tradeoff. – asmeurer Feb 25 '20 at 06:11
  • I guess the question now is, how hard is it to make a pure elisp version of line-number-mode? linum-mode has the alignment issue I mentioned. I'm not sure about the performance differences. I never noticed problems with linum-mode, but I have it always on, so it's possible I did see problems but never knew that was what was causing it. – asmeurer Feb 25 '20 at 06:13
  • In the initial post to the Emacs Devel mailing list described above, I changed `pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display);` to `pint2str (lnum_buf, it->lnum_width, lnum_to_display);` and I changed `strcat (lnum_buf, " ");` to `strcat (lnum_buf, "|");` -- the screenshots were taken after making those changes and rebuilding from source. I am using languages that read from left to right (English and Spanish), so the `|` falls between the line numbers and the text. I used Lisp line numbers for years before the built-in line numbers written in C -- the C version is much quicker. – lawlist Feb 25 '20 at 06:19
  • In one of my rough drafts, I changed `pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display);` to `pint2str (lnum_buf, it->lnum_width, lnum_to_display);` and I commented out `strcat (lnum_buf, " ");` -- resulting in no space/padding on the left and no space/padding on the right. In my own custom setup used currently, I opted to eliminate the space on the left and keep the space on the right, without using any special character like the `|` symbol, because word-wrapped lines would need some extra coding to insert a `|` symbol on those lines where no line number exists. – lawlist Feb 25 '20 at 06:25