I would like that my linum-mode
numbering is right aligned. The closest thing I've found is on emacswiki, but it doesn't work - it seems to left align the digits instead of right align it. The snippet is found here. Sorry for the horrible indenting, lisp is pretty alien to me :)
(setq linum-format
(lambda (line)
(propertize
(format
(let
((w (length (number-to-string (count-lines (point-min)
(point-max))))))
(concat "%" (number-to-string w) "d ")) line) 'face 'linum)))
Any ideas?
You can just use the value 'dynamic
so you don't have to choose an arbitrary amount of padding:
(custom-set-variables '(linum-format 'dynamic))
Or you can also customize it with: M-x customize-variable RET linum-format
Also, @asmeurer asked how to still add a space after the number with dynamic
. There is no easy way to do that, but it can be accomplished using defadvice
around the linum-update-window
function that I adapted from the code for dynamic
that is already in that function:
(defadvice linum-update-window (around linum-dynamic activate)
(let* ((w (length (number-to-string
(count-lines (point-min) (point-max)))))
(linum-format (concat "%" (number-to-string w) "d ")))
ad-do-it))
Customize variable linum-format, for example to align on the right on 7 characters :
(custom-set-variables '(linum-format (quote "%7d")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With