Bring back nlinum-hl

I moved the nlinum--region fix to the nlinum-hl package; which also
contains fixes for other problematic major-modes.
This commit is contained in:
Henrik Lissner 2017-06-14 02:51:24 +02:00
parent 63b091f7aa
commit 6dff6e124b
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -282,34 +282,6 @@ file."
:config
(setq nlinum-highlight-current-line t)
;; fix for disappearing line numbers in nlinum
;; <https://github.com/hlissner/.emacs.d/issues/59#issuecomment-306937318>
(defun doom*nlinum-region (start limit)
(save-excursion
(let ((inhibit-point-motion-hooks t))
(goto-char start)
(unless (bolp) (forward-line 1))
(remove-overlays (point) limit 'nlinum t)
(let ((line (nlinum--line-number-at-pos)))
(while
(and (not (eobp)) (<= (point) limit)
(let* ((ol (make-overlay (point) (1+ (point))))
(str (funcall nlinum-format-function
line nlinum--width))
(width (string-width str)))
(when (< nlinum--width width)
(setq nlinum--width width)
(nlinum--flush))
(overlay-put ol 'nlinum t)
(overlay-put ol 'evaporate t)
(overlay-put ol 'before-string
(propertize " " 'display
`((margin left-margin) ,str)))
(setq line (1+ line))
(zerop (forward-line 1))))))))
nil)
(advice-add #'nlinum--region :override #'doom*nlinum-region)
;; Optimization: calculate line number column width beforehand
(defun doom|init-nlinum-width ()
(setq nlinum--width
@ -317,6 +289,24 @@ file."
(format-mode-line "%l")))))
(add-hook 'nlinum-mode-hook #'doom|init-nlinum-width))
;; Fixes disappearing line numbers in nlinum and other quirks
(def-package! nlinum-hl
:load-path "~/work/plugins/emacs-nlinum-hl/"
:after nlinum
:config
;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode',
;; line numbers tend to vanish next to code blocks.
(advice-add #'markdown-fontify-code-block-natively
:after #'nlinum-hl-do-markdown-fontify-region)
;; When using `web-mode's code-folding an entire range of line numbers will
;; vanish in the affected area.
(advice-add #'web-mode-fold-or-unfold :after #'nlinum-hl-do-generic-flush)
;; Changing fonts can leave nlinum line numbers in their original size; this
;; forces them to resize.
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk
;; languages like Lisp.
(def-package! rainbow-delimiters