0

When I enable linum-mode in the scratch buffer (and most other buffers I tried) there is no space to the left of the line numbers. Although when enable linum-mode in the .emacs configuration file, I get space to the left of the line numbers. Here is a picture: enter image description here

How can I control the format of the line numbers? I'd like at least one space to the left of the numbers (like in the .emacs file) in all files.

  • Does your .emacs file have more than 99 lines? If so, that would explain the extra space in the first 99 lines, but after that there is (probably) no space. – NickD Dec 3 '19 at 2:49
  • Oh snap! Yes, you’re right. I feel like an idiot haha ... Nontheless, how can I stick at least one space to the left of line numbers? – scribe Dec 3 '19 at 2:58
2

You could customize the variable linum-format to be a format string that begins with a space. The simplest would be (setq linum-format " %d") which sticks one space in front of the formatted digit. I tried it out and it looks slightly weird:

enter image description here

The other thing is that if you're on Emacs 26, there is a new line number mode display-line-numbers-mode which is "new and improved" and has some space on the left by default:

enter image description here

| improve this answer | |
  • Huh, I did try linum-format before posting this question and it did not work but now it is. That weirdness you see is because the numbers are no longer dynamically right aligned. The format string "%d" means 'take only as many spaces as you need', so even when you do %-d, it takes exactly as much space as it needs and the numbers look left aligned. – scribe Dec 3 '19 at 4:45
  • Also, I use Ubuntu and am on 25.2.2, I installed Emacs using the usual apt install. When are they going to update Emacs in their repository, I think even Emacs 27 is out now. – scribe Dec 3 '19 at 4:48
  • i think 26.3 is the latest stable release. I'm on PureOS which gets updates from debian, and it has 26.1. I dunno whats up with your Ubuntu :) – shoshin Dec 3 '19 at 4:51
  • I tried sudo apt-get upgrade emacs and got emacs is already the newest version (47.0). Great now I don't understand the versioning. What does 47 mean if I am at 25.something. Is this your version too? – scribe Dec 3 '19 at 4:58
  • no, mine has this emacs is already the newest version (1:26.1+1-3.2+deb10u1) i was quite confused about it, but found out it is a patched version of 26.1. i do remember seeing those confusing higher version numbers on a different OS, but I'm not sure what they indicate. you can just do emacs --version to get the truth – shoshin Dec 3 '19 at 5:04
0

FWIW (setq nlinum-format " %d") works with nlinum-mode (available from your nearest GNU ELPA repository) and still right-aligns the numbers.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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