Skip to content

Instantly share code, notes, and snippets.

@whitlockjc
Created March 9, 2016 18:25
Show Gist options
  • Save whitlockjc/33fdf9bbdb9758dc2cbb to your computer and use it in GitHub Desktop.
Save whitlockjc/33fdf9bbdb9758dc2cbb to your computer and use it in GitHub Desktop.
Emacs linum-format that works around whitespace-mode and padding
;; Linum mode
(global-linum-mode t)
;; Custom face/function to pad the line number in a way that does not conflict with whitespace-mode
(defface linum-padding
`((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 " " 'face 'linum-padding)
(propertize (make-string (- w (length (number-to-string line))) ?0)
'face 'linum-padding)
(propertize (number-to-string line) 'face 'linum)
(propertize " " 'face 'linum-padding)
)))
(setq linum-format 'linum-format-func)
@tam5
Copy link

tam5 commented Apr 25, 2018

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment