Optimize nlinum config
This commit is contained in:
parent
74a398de5e
commit
32112605fa
1 changed files with 11 additions and 9 deletions
|
@ -179,20 +179,22 @@
|
||||||
(defun narf|nlinum-unhl-line ()
|
(defun narf|nlinum-unhl-line ()
|
||||||
"Unhighlight line number"
|
"Unhighlight line number"
|
||||||
(when narf--hl-nlinum-overlay
|
(when narf--hl-nlinum-overlay
|
||||||
(let* ((ov narf--hl-nlinum-overlay)
|
(let* ((disp (get-text-property
|
||||||
(disp (get-text-property 0 'display (overlay-get ov 'before-string)))
|
0 'display (overlay-get narf--hl-nlinum-overlay 'before-string)))
|
||||||
(str (nth 1 disp)))
|
(str (nth 1 disp)))
|
||||||
(put-text-property 0 (length str) 'face 'linum str)
|
(put-text-property 0 (length str) 'face 'linum str)
|
||||||
(setq narf--hl-nlinum-overlay nil
|
(setq narf--hl-nlinum-overlay nil
|
||||||
narf--hl-nlinum-line nil))))
|
narf--hl-nlinum-line nil)
|
||||||
|
disp)))
|
||||||
|
|
||||||
(defun narf|nlinum-hl-line (&optional line)
|
(defun narf|nlinum-hl-line (&optional line)
|
||||||
"Highlight line number"
|
"Highlight line number"
|
||||||
(let ((line-no (or line (string-to-number (format-mode-line "%l")))))
|
(let ((line-no (or line (string-to-number (format-mode-line "%l")))))
|
||||||
(when (and nlinum-mode (not (eq line-no narf--hl-nlinum-line)))
|
(when (and nlinum-mode (not (eq line-no narf--hl-nlinum-line)))
|
||||||
(let* ((pbol (if line (save-excursion (goto-char (point-min))
|
(let* ((pbol (if line
|
||||||
(forward-line line-no)
|
(save-excursion (goto-char (point-min))
|
||||||
(point-at-bol))
|
(forward-line line-no)
|
||||||
|
(line-beginning-position))
|
||||||
(line-beginning-position)))
|
(line-beginning-position)))
|
||||||
(peol (1+ pbol)))
|
(peol (1+ pbol)))
|
||||||
;; Handle EOF case
|
;; Handle EOF case
|
||||||
|
@ -200,8 +202,7 @@
|
||||||
(when (>= peol max)
|
(when (>= peol max)
|
||||||
(setq peol max)))
|
(setq peol max)))
|
||||||
(jit-lock-fontify-now pbol peol)
|
(jit-lock-fontify-now pbol peol)
|
||||||
(let* ((overlays (overlays-in pbol peol))
|
(let ((ov (-first (lambda (item) (overlay-get item 'nlinum)) (overlays-in pbol peol))))
|
||||||
(ov (-first (lambda (item) (overlay-get item 'nlinum)) overlays)))
|
|
||||||
(when ov
|
(when ov
|
||||||
(narf|nlinum-unhl-line)
|
(narf|nlinum-unhl-line)
|
||||||
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
|
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
|
||||||
|
@ -211,7 +212,8 @@
|
||||||
|
|
||||||
(add-hook! nlinum-mode
|
(add-hook! nlinum-mode
|
||||||
(setq nlinum--width
|
(setq nlinum--width
|
||||||
(length (int-to-string (count-lines (point-min) (point-max)))))))
|
(length (save-excursion (goto-char (point-max))
|
||||||
|
(format-mode-line "%l"))))))
|
||||||
|
|
||||||
|
|
||||||
;; Mode-line ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; Mode-line ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue