From 7ba22d0d8676907d83db9f6b7f5575583309ff0e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 9 Jun 2017 13:48:00 +0200 Subject: [PATCH] Possibly fix disappearing line numbers (#59) --- core/core-ui.el | 39 ++++++++++++++++++++++++++++----------- core/packages.el | 1 - 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index 282a3411f..2ed87bce3 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -262,23 +262,40 @@ file." :config (setq nlinum-highlight-current-line t) + ;; fix for disappearing line numbers in nlinum + ;; + (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 (add-hook! nlinum-mode (setq nlinum--width (length (save-excursion (goto-char (point-max)) (format-mode-line "%l")))))) -;; Highlight current line, and other nlinum tweaks/fixes -(def-package! nlinum-hl - :after nlinum - :init (add-hook 'nlinum-mode-hook #'nlinum-hl-mode) - :config - ;; nlinum has a tendency to lose line numbers over time; a known issue. These - ;; hooks/advisors attempt to stave off these glitches. - (advice-add #'select-window :before #'nlinum-hl-do-flush) - (advice-add #'select-window :after #'nlinum-hl-do-flush) - (add-hook '+evil-esc-hook #'nlinum-hl-flush-all-windows t)) - ;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk ;; languages like Lisp. (def-package! rainbow-delimiters diff --git a/core/packages.el b/core/packages.el index b43e7962e..fafc83011 100644 --- a/core/packages.el +++ b/core/packages.el @@ -18,7 +18,6 @@ (package! highlight-indentation) (package! highlight-numbers) (package! nlinum) -(package! nlinum-hl) (package! rainbow-delimiters) (package! vi-tilde-fringe) (package! visual-fill-column)