3

Currently my buffer with linum mode and white space mode enabled looks like this:

enter image description here

How do I configure the linum region to not render the whitespace symbols?

bneil
  • 1,590
  • 3
  • 16
  • 26

2 Answers2

3

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)))
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • Your `linum-format` function is inefficient (exactly as linum itself used to be, mind; but it's been fixed). Specifically, you are re-generating the format -- running `(count-lines (point-min) (point-max))` -- for each line on the screen. See http://stackoverflow.com/a/11496199/324105 for an example of how to fix this. – phils Oct 23 '13 at 20:23
3

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)))))
Julia Path
  • 2,356
  • 15
  • 21