doomemacs/core/defuns/defuns-nlinum.el

51 lines
1.5 KiB
EmacsLisp
Raw Normal View History

2015-06-06 06:40:33 -04:00
;;; defuns-nlinum.el
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/nlinum-toggle ()
2015-06-06 06:40:33 -04:00
(interactive)
(if (bound-and-true-p nlinum-mode)
2016-05-20 22:37:30 -04:00
(doom|nlinum-disable)
(doom|nlinum-enable)))
2015-06-06 06:40:33 -04:00
2016-05-06 01:57:50 -04:00
;;;###autoload
2016-05-23 20:56:19 -04:00
(defun doom|nlinum-enable (&rest _)
2016-05-06 01:57:50 -04:00
(nlinum-mode +1)
2016-05-20 22:37:30 -04:00
(add-hook 'post-command-hook 'doom|nlinum-hl-line nil t)
(doom--nlinum-unhl-line))
2016-05-06 01:57:50 -04:00
2016-03-23 11:51:29 -04:00
;;;###autoload
2016-05-23 20:56:19 -04:00
(defun doom|nlinum-disable (&rest _)
2016-04-30 23:13:39 -04:00
(nlinum-mode -1)
2016-05-20 22:37:30 -04:00
(remove-hook 'post-command-hook 'doom|nlinum-hl-line t)
(doom--nlinum-unhl-line))
2016-04-30 23:13:39 -04:00
(defun doom--nlinum-unhl-line ()
2016-04-30 23:13:39 -04:00
"Unhighlight line number"
2016-05-20 22:37:30 -04:00
(when doom--hl-nlinum-overlay
2016-04-30 23:13:39 -04:00
(let* ((disp (get-text-property
2016-05-20 22:37:30 -04:00
0 'display (overlay-get doom--hl-nlinum-overlay 'before-string)))
2016-04-30 23:13:39 -04:00
(str (nth 1 disp)))
(put-text-property 0 (length str) 'face 'linum str)
(setq doom--hl-nlinum-overlay nil)
2016-04-30 23:13:39 -04:00
disp)))
;;;###autoload
2016-09-05 12:24:16 +02:00
(defun doom|nlinum-hl-line (&rest _)
2016-04-30 23:13:39 -04:00
"Highlight line number"
(let* ((pbol (line-beginning-position))
(peol (1+ pbol))
(max (point-max)))
;; Handle EOF case
(when (>= peol max)
(setq peol max))
(jit-lock-fontify-now pbol peol)
(let ((ov (--first (overlay-get it 'nlinum) (overlays-in pbol peol))))
(doom--nlinum-unhl-line)
(when ov
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
(put-text-property 0 (length str) 'face 'doom-nlinum-highlight str)
(setq doom--hl-nlinum-overlay ov))))))
2016-03-23 11:51:29 -04:00
2015-06-06 06:40:33 -04:00
(provide 'defuns-nlinum)
;;; defuns-nlinum.el ends here