Fix whitespace-mode space-marks in nlinum (#109)
...by changing the padding character in line numbers.
This commit is contained in:
parent
3d6bd3f3f0
commit
d3270a9b00
1 changed files with 21 additions and 2 deletions
|
@ -268,8 +268,9 @@ file."
|
||||||
(def-package! nlinum
|
(def-package! nlinum
|
||||||
:commands nlinum-mode
|
:commands nlinum-mode
|
||||||
:preface
|
:preface
|
||||||
(defvar linum-format "%3d ")
|
(defvar doom-ui-nlinum-lpad 4)
|
||||||
(defvar nlinum-format "%4d ")
|
(defvar doom-ui-nlinum-rpad 1)
|
||||||
|
(defvar doom-ui-nlinum-spacer ?\u2002)
|
||||||
:init
|
:init
|
||||||
(defun doom|init-nlinum-mode ()
|
(defun doom|init-nlinum-mode ()
|
||||||
(unless (eq major-mode 'org-mode)
|
(unless (eq major-mode 'org-mode)
|
||||||
|
@ -278,6 +279,24 @@ file."
|
||||||
:config
|
:config
|
||||||
(setq nlinum-highlight-current-line t)
|
(setq nlinum-highlight-current-line t)
|
||||||
|
|
||||||
|
(defun doom-nlinum-format-fn (line width)
|
||||||
|
"A more customizable `nlinum-format-function'. See `doom-ui-nlinum-lpad',
|
||||||
|
`doom-ui-nlinum-rpad' and `doom-ui-nlinum-spacer'. Allows a fix for
|
||||||
|
`whitespace-mode' space-marks appearing inside the line number."
|
||||||
|
(let ((str (number-to-string line)))
|
||||||
|
(setq str (concat (make-string (max 0 (- doom-ui-nlinum-lpad (length str)))
|
||||||
|
doom-ui-nlinum-spacer)
|
||||||
|
str
|
||||||
|
(make-string doom-ui-nlinum-rpad doom-ui-nlinum-spacer)))
|
||||||
|
(put-text-property 0 (length str) 'face
|
||||||
|
(if (and nlinum-highlight-current-line
|
||||||
|
(= line nlinum--current-line))
|
||||||
|
'nlinum-current-line
|
||||||
|
'linum)
|
||||||
|
str)
|
||||||
|
str))
|
||||||
|
(setq nlinum-format-function #'doom-nlinum-format-fn)
|
||||||
|
|
||||||
;; Optimization: calculate line number column width beforehand
|
;; Optimization: calculate line number column width beforehand
|
||||||
(defun doom|init-nlinum-width ()
|
(defun doom|init-nlinum-width ()
|
||||||
(setq nlinum--width
|
(setq nlinum--width
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue