2015-06-06 06:40:33 -04:00
|
|
|
;;; defuns-nlinum.el
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf/nlinum-toggle ()
|
|
|
|
(interactive)
|
2015-07-18 12:14:16 +02:00
|
|
|
(if (bound-and-true-p nlinum-mode)
|
2015-06-06 06:40:33 -04:00
|
|
|
(narf|nlinum-disable)
|
|
|
|
(narf|nlinum-enable)))
|
|
|
|
|
2016-05-06 01:57:50 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun narf|nlinum-enable ()
|
|
|
|
(nlinum-mode +1)
|
|
|
|
(add-hook 'post-command-hook 'narf|nlinum-hl-line nil t)
|
|
|
|
(narf|nlinum-unhl-line))
|
|
|
|
|
2016-03-23 11:51:29 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun narf|nlinum-disable ()
|
2016-04-30 23:13:39 -04:00
|
|
|
(nlinum-mode -1)
|
|
|
|
(remove-hook 'post-command-hook 'narf|nlinum-hl-line t)
|
|
|
|
(narf|nlinum-unhl-line))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf|nlinum-unhl-line ()
|
|
|
|
"Unhighlight line number"
|
|
|
|
(when narf--hl-nlinum-overlay
|
|
|
|
(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)
|
|
|
|
disp)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun narf|nlinum-hl-line (&optional line)
|
|
|
|
"Highlight line number"
|
|
|
|
(let ((line-no (or line (string-to-number (format-mode-line "%l")))))
|
|
|
|
(if (and nlinum-mode (not (eq line-no narf--hl-nlinum-line)))
|
|
|
|
(let* ((pbol (if line
|
|
|
|
(save-excursion (goto-char 1)
|
|
|
|
(forward-line line-no)
|
|
|
|
(line-beginning-position))
|
|
|
|
(line-beginning-position)))
|
|
|
|
(peol (1+ pbol))
|
|
|
|
(max (point-max)))
|
|
|
|
;; Handle EOF case
|
|
|
|
(when (>= peol max)
|
|
|
|
(setq peol max))
|
|
|
|
(jit-lock-fontify-now pbol peol)
|
2016-05-12 02:38:09 -04:00
|
|
|
(let ((ov (--first (overlay-get it 'nlinum) (overlays-in pbol peol))))
|
2016-04-30 23:13:39 -04:00
|
|
|
(when ov
|
|
|
|
(narf|nlinum-unhl-line)
|
|
|
|
(let ((str (nth 1 (get-text-property 0 'display (overlay-get ov 'before-string)))))
|
|
|
|
(put-text-property 0 (length str) 'face 'linum-highlight-face str)
|
|
|
|
(setq narf--hl-nlinum-overlay ov
|
|
|
|
narf--hl-nlinum-line line-no))))))))
|
2016-03-23 11:51:29 -04:00
|
|
|
|
2015-06-06 06:40:33 -04:00
|
|
|
(provide 'defuns-nlinum)
|
|
|
|
;;; defuns-nlinum.el ends here
|