Bring back nlinum
linum-mode *really* slows down buffers when they're displayed in more than one window. This lag isn't present in nlinum. nlinum isn't perfect either but... lesser of two evils. This includes advisors and an ESC hook to mitigate the issue of disappearing nlinum line numbers.
This commit is contained in:
parent
db6de01b16
commit
8ca6e2630b
5 changed files with 54 additions and 11 deletions
|
@ -13,7 +13,13 @@
|
|||
(defun doom/toggle-line-numbers (&optional arg)
|
||||
"Toggle `linum-mode'."
|
||||
(interactive "P")
|
||||
(linum-mode (or arg (if linum-mode -1 +1))))
|
||||
(let ((arg (or arg (if linum-mode -1 +1))))
|
||||
(cond ((featurep 'nlinum)
|
||||
(nlinum-mode arg))
|
||||
((featurep 'linum-mode)
|
||||
(linum-mode arg))
|
||||
(t
|
||||
(error "No line number plugin detected")))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-resize-window (new-size &optional horizontal)
|
||||
|
|
|
@ -195,18 +195,51 @@ file."
|
|||
(add-hook 'evil-visual-state-entry-hook #'doom|hl-line-off nil t)
|
||||
(add-hook 'evil-visual-state-exit-hook #'hl-line-mode nil t)))))
|
||||
|
||||
;; Line numbers
|
||||
(def-package! linum
|
||||
:commands linum-mode
|
||||
:preface (defvar linum-format "%4d ")
|
||||
;; Line number column. A faster (or equivalent, in the worst case) line number
|
||||
;; plugin than the built-in `linum'.
|
||||
(def-package! nlinum
|
||||
:commands nlinum-mode
|
||||
:preface
|
||||
(defvar linum-format "%3d ")
|
||||
(defvar nlinum-format "%4d ")
|
||||
:init
|
||||
(add-hook! (prog-mode text-mode)
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(linum-mode +1)))
|
||||
(nlinum-mode +1)))
|
||||
|
||||
:config
|
||||
(require 'hlinum) ; highlight current line number
|
||||
(hlinum-activate))
|
||||
(defun doom*nlinum-flush-all-windows (&rest _)
|
||||
"Fix nlinum margins after major UI changes (like a change of font)."
|
||||
(dolist (buffer (doom-visible-buffers))
|
||||
(with-current-buffer buffer
|
||||
(when nlinum-mode (nlinum--flush)))))
|
||||
(advice-add #'set-frame-font :after #'doom*nlinum-flush-all-windows)
|
||||
|
||||
;; A known issue with nlinum is that line numbers disappear over time. These
|
||||
;; hooks/advisors will attempt to stave off these glitches.
|
||||
(defun doom*nlinum-flush (&optional _ norecord)
|
||||
;; norecord check is necessary to prevent infinite recursion in
|
||||
;; `select-window'
|
||||
(when (and nlinum-mode (not norecord))
|
||||
(if _
|
||||
(nlinum--flush)
|
||||
;; done in two steps to leave current line number highlighting alone
|
||||
(nlinum--region (point-min) (line-beginning-position))
|
||||
(nlinum--region (line-end-position) (point-max)))))
|
||||
;; refresh when switching windows
|
||||
(advice-add #'select-window :before #'doom*nlinum-flush)
|
||||
(advice-add #'select-window :after #'doom*nlinum-flush)
|
||||
;; and when pressing ESC in normal mode
|
||||
(add-hook '+evil-esc-hook #'doom*nlinum-flush)
|
||||
|
||||
;;
|
||||
(after! web-mode
|
||||
(advice-add #'web-mode-fold-or-unfold :after #'nlinum--flush))
|
||||
|
||||
;; 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"))))))
|
||||
|
||||
;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk
|
||||
;; languages like Lisp.
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
;; core-ui.el
|
||||
(package! highlight-indentation)
|
||||
(package! highlight-numbers)
|
||||
(package! hlinum)
|
||||
(package! nlinum)
|
||||
(package! rainbow-delimiters)
|
||||
(package! vi-tilde-fringe)
|
||||
(package! visual-fill-column)
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
(with-current-buffer +regex--expr-buffer
|
||||
(conf-mode)
|
||||
(rainbow-delimiters-mode +1)
|
||||
(linum-mode -1)
|
||||
(doom/toggle-line-numbers +1)
|
||||
(setq-local require-final-newline nil)
|
||||
(+regex-mode +1)
|
||||
(text-scale-set 3)))
|
||||
|
@ -98,7 +98,7 @@
|
|||
(switch-to-buffer (get-buffer-create "*doom-regex-repl*"))
|
||||
(conf-mode)
|
||||
(rainbow-delimiters-mode +1)
|
||||
(linum-mode -1)
|
||||
(doom/toggle-line-numbers -1)
|
||||
(setq-local require-final-newline nil)
|
||||
(setq mode-line-format nil
|
||||
+regex--expr-replace-buffer (current-buffer))
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
:config
|
||||
(load-theme +doom-theme t)
|
||||
|
||||
;; nlinum line highlighting
|
||||
(when (featurep 'nlinum)
|
||||
(doom-themes-nlinum-config))
|
||||
|
||||
;; Add file icons to doom-neotree
|
||||
(doom-themes-neotree-config)
|
||||
(setq doom-neotree-enable-variable-pitch t
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue