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 ()
|
||||
"Unhighlight line number"
|
||||
(when narf--hl-nlinum-overlay
|
||||
(let* ((ov narf--hl-nlinum-overlay)
|
||||
(disp (get-text-property 0 'display (overlay-get ov 'before-string)))
|
||||
(let* ((disp (get-text-property
|
||||
0 'display (overlay-get narf--hl-nlinum-overlay 'before-string)))
|
||||
(str (nth 1 disp)))
|
||||
(put-text-property 0 (length str) 'face 'linum str)
|
||||
(setq narf--hl-nlinum-overlay nil
|
||||
narf--hl-nlinum-line nil))))
|
||||
narf--hl-nlinum-line nil)
|
||||
disp)))
|
||||
|
||||
(defun narf|nlinum-hl-line (&optional line)
|
||||
"Highlight line number"
|
||||
(let ((line-no (or line (string-to-number (format-mode-line "%l")))))
|
||||
(when (and nlinum-mode (not (eq line-no narf--hl-nlinum-line)))
|
||||
(let* ((pbol (if line (save-excursion (goto-char (point-min))
|
||||
(forward-line line-no)
|
||||
(point-at-bol))
|
||||
(let* ((pbol (if line
|
||||
(save-excursion (goto-char (point-min))
|
||||
(forward-line line-no)
|
||||
(line-beginning-position))
|
||||
(line-beginning-position)))
|
||||
(peol (1+ pbol)))
|
||||
;; Handle EOF case
|
||||
|
@ -200,8 +202,7 @@
|
|||
(when (>= peol max)
|
||||
(setq peol max)))
|
||||
(jit-lock-fontify-now pbol peol)
|
||||
(let* ((overlays (overlays-in pbol peol))
|
||||
(ov (-first (lambda (item) (overlay-get item 'nlinum)) overlays)))
|
||||
(let ((ov (-first (lambda (item) (overlay-get item 'nlinum)) (overlays-in pbol peol))))
|
||||
(when ov
|
||||
(narf|nlinum-unhl-line)
|
||||
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
|
||||
|
@ -211,7 +212,8 @@
|
|||
|
||||
(add-hook! nlinum-mode
|
||||
(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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue