Currently my buffer with linum mode and white space mode enabled looks like this:
How do I configure the linum region to not render the whitespace symbols?
Observation: There is no need for spaces to the right of the line numbers (as shown in the question), because the fringe width can be used to control separation between the line numbers and the body.
(setq-default left-fringe-width 10)
(setq-default right-fringe-width 0)
(set-face-attribute 'fringe nil :background "black")
Option # 1: However, this is not flush-right.
(setq linum-format "%d")
Option # 2: Use leading zeros -- is flush-right.
(eval-after-load 'linum
'(progn
(defface linum-leading-zero
`((t :inherit 'linum
:foreground ,(face-attribute 'linum :background nil t)))
"Face for displaying leading zeroes for line numbers in display margin."
:group 'linum)
(defun linum-format-func (line)
(let ((w (length
(number-to-string (count-lines (point-min) (point-max))))))
(concat
(propertize (make-string (- w (length (number-to-string line))) ?0)
'face 'linum-leading-zero)
(propertize (number-to-string line) 'face 'linum))))
(setq linum-format 'linum-format-func)))
You could improve @lawlists second solution, but instead of using 0s as a space replacement, you can use some exotic whitespace like the en-space which would be "\u2002"
. Since we aren't using proportional fonts that will look just like a space, but whitespace
won't mess with it.
I'm actually using linum-relative-mode
where you can conveniently just advice linum-relative
:
(advice-add 'linum-relative :filter-return
(lambda (num)
(if (not (get-text-property 0 'invisible num))
(propertize (replace-regexp-in-string " " "\u2002" num)
'face (get-text-property 0 'face num)))))