Refactor line number implementation
+ Add relative line number support (see doom-line-numbers-style) + Update doom/toggle-line-numbers + New hook functions: doom|enable-line-numbers, doom|disable-line-numbers Addresses #156
This commit is contained in:
parent
3bf876f44e
commit
f2d8681ef4
4 changed files with 123 additions and 88 deletions
|
@ -14,11 +14,14 @@
|
||||||
"Toggle `linum-mode'."
|
"Toggle `linum-mode'."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(cond ((boundp 'display-line-numbers)
|
(cond ((boundp 'display-line-numbers)
|
||||||
(setq display-line-numbers (not display-line-numbers)))
|
(setq display-line-numbers
|
||||||
|
(pcase arg
|
||||||
|
('(4) 'relative)
|
||||||
|
(1 t)
|
||||||
|
(-1 nil)
|
||||||
|
(_ (not display-line-numbers)))))
|
||||||
((featurep 'nlinum)
|
((featurep 'nlinum)
|
||||||
(nlinum-mode (or arg (if nlinum-mode -1 +1))))
|
(nlinum-mode (or arg (if nlinum-mode -1 +1))))
|
||||||
((featurep 'linum)
|
|
||||||
(linum-mode (or arg (if linum-mode -1 +1))))
|
|
||||||
(t
|
(t
|
||||||
(error "No line number plugin detected"))))
|
(error "No line number plugin detected"))))
|
||||||
|
|
||||||
|
|
144
core/core-ui.el
144
core/core-ui.el
|
@ -25,21 +25,6 @@
|
||||||
return a string). This changes the 'long' name of a major-mode, allowing for
|
return a string). This changes the 'long' name of a major-mode, allowing for
|
||||||
shorter major mode name in the mode-line. See `doom|set-mode-name'.")
|
shorter major mode name in the mode-line. See `doom|set-mode-name'.")
|
||||||
|
|
||||||
;; Line numbers
|
|
||||||
(defvar doom-line-number-lpad 4
|
|
||||||
"How much padding to place before line numbers.")
|
|
||||||
|
|
||||||
(defvar doom-line-number-rpad 1
|
|
||||||
"How much padding to place after line numbers.")
|
|
||||||
|
|
||||||
(defvar doom-line-number-pad-char 32
|
|
||||||
"Character to use for padding line numbers.
|
|
||||||
|
|
||||||
By default, this is a space key. If you use `whitespace-mode' with `space-mark',
|
|
||||||
the whitespace in line numbers will be affected (this can look ugly). In this
|
|
||||||
case, you can change this to ?\u2002, which is a unicode character that looks
|
|
||||||
like a space that `whitespace-mode' won't affect.")
|
|
||||||
|
|
||||||
|
|
||||||
;; Hook(s)
|
;; Hook(s)
|
||||||
(defvar doom-init-ui-hook nil
|
(defvar doom-init-ui-hook nil
|
||||||
|
@ -73,6 +58,7 @@ like a space that `whitespace-mode' won't affect.")
|
||||||
bidi-display-reordering nil ; disable bidirectional text for tiny performance boost
|
bidi-display-reordering nil ; disable bidirectional text for tiny performance boost
|
||||||
blink-matching-paren nil ; don't blink--too distracting
|
blink-matching-paren nil ; don't blink--too distracting
|
||||||
cursor-in-non-selected-windows nil ; hide cursors in other windows
|
cursor-in-non-selected-windows nil ; hide cursors in other windows
|
||||||
|
display-line-numbers-width 3
|
||||||
frame-inhibit-implied-resize t
|
frame-inhibit-implied-resize t
|
||||||
;; remove continuation arrow on right fringe
|
;; remove continuation arrow on right fringe
|
||||||
fringe-indicator-alist (delq (assq 'continuation fringe-indicator-alist)
|
fringe-indicator-alist (delq (assq 'continuation fringe-indicator-alist)
|
||||||
|
@ -256,13 +242,6 @@ local value, whether or not it's permanent-local. Therefore, we cycle
|
||||||
(add-hook! '(doom-post-init-hook minibuffer-setup-hook)
|
(add-hook! '(doom-post-init-hook minibuffer-setup-hook)
|
||||||
#'doom|no-fringes-in-minibuffer)
|
#'doom|no-fringes-in-minibuffer)
|
||||||
|
|
||||||
;; line numbers in newer version of Emacs
|
|
||||||
(when (boundp 'display-line-numbers)
|
|
||||||
(defun doom|init-line-numbers ()
|
|
||||||
(unless (eq major-mode 'org-mode)
|
|
||||||
(setq display-line-numbers t)))
|
|
||||||
(add-hook! (prog-mode text-mode) #'doom|init-line-numbers))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Plugins
|
;; Plugins
|
||||||
|
@ -312,10 +291,6 @@ local value, whether or not it's permanent-local. Therefore, we cycle
|
||||||
(setq hl-line-sticky-flag nil
|
(setq hl-line-sticky-flag nil
|
||||||
global-hl-line-sticky-flag nil)
|
global-hl-line-sticky-flag nil)
|
||||||
|
|
||||||
;; Fix lingering hl-line overlays
|
|
||||||
(add-hook! 'hl-line-mode-hook
|
|
||||||
(remove-overlays (point-min) (point-max) 'face 'hl-line))
|
|
||||||
|
|
||||||
(after! evil
|
(after! evil
|
||||||
;; Disable `hl-line' in evil-visual mode (temporarily). `hl-line' can make
|
;; Disable `hl-line' in evil-visual mode (temporarily). `hl-line' can make
|
||||||
;; the selection region harder to see while in evil visual mode.
|
;; the selection region harder to see while in evil visual mode.
|
||||||
|
@ -324,21 +299,91 @@ local value, whether or not it's permanent-local. Therefore, we cycle
|
||||||
(add-hook 'evil-visual-state-entry-hook #'doom|turn-off-hl-line)
|
(add-hook 'evil-visual-state-entry-hook #'doom|turn-off-hl-line)
|
||||||
(add-hook 'evil-visual-state-exit-hook #'hl-line-mode)))
|
(add-hook 'evil-visual-state-exit-hook #'hl-line-mode)))
|
||||||
|
|
||||||
;; Line number column. A faster (or equivalent, in the worst case) line number
|
;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk
|
||||||
;; plugin than the built-in `linum'. This will be ignored if you're using Emacs
|
;; languages like Lisp.
|
||||||
;; 26.1+, which has native line number support.
|
(def-package! rainbow-delimiters
|
||||||
(def-package! nlinum
|
:commands rainbow-delimiters-mode
|
||||||
:unless (boundp 'display-line-numbers)
|
:config (setq rainbow-delimiters-max-face-count 3)
|
||||||
|
:init (add-hook 'lisp-mode-hook #'rainbow-delimiters-mode))
|
||||||
|
|
||||||
|
;; indicators for empty lines past EOF
|
||||||
|
(def-package! vi-tilde-fringe
|
||||||
|
:commands global-vi-tilde-fringe-mode
|
||||||
|
:init (add-hook 'doom-init-hook #'global-vi-tilde-fringe-mode))
|
||||||
|
|
||||||
|
;; For a distractions-free-like UI, that dynamically resizes margets and can
|
||||||
|
;; center a buffer.
|
||||||
|
(def-package! visual-fill-column
|
||||||
|
:commands visual-fill-column-mode
|
||||||
|
:config
|
||||||
|
(setq-default visual-fill-column-center-text nil
|
||||||
|
visual-fill-column-width fill-column))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Line numbers
|
||||||
|
;;
|
||||||
|
|
||||||
|
(defvar doom-line-numbers-style t
|
||||||
|
"The style to use for the line number display.
|
||||||
|
|
||||||
|
Accepts the same arguments as `display-line-numbers', which are:
|
||||||
|
|
||||||
|
nil No line numbers
|
||||||
|
t Ordinary line numbers
|
||||||
|
'relative Relative line numbers")
|
||||||
|
|
||||||
|
(defun doom|enable-line-numbers (&optional arg)
|
||||||
|
"Enables the display of line numbers, using `display-line-numbers' (in Emacs
|
||||||
|
26+) or `nlinum-mode'.
|
||||||
|
|
||||||
|
See `doom-line-numbers-style' to control the style of line numbers to display."
|
||||||
|
(cond ((boundp 'display-line-numbers)
|
||||||
|
(setq display-line-numbers
|
||||||
|
(pcase arg
|
||||||
|
(+1 doom-line-numbers-style)
|
||||||
|
(-1 nil)
|
||||||
|
(_ doom-line-numbers-style))))
|
||||||
|
((eq doom-line-numbers-style 'relative)
|
||||||
|
(if (= arg -1)
|
||||||
|
(nlinum-relative-off)
|
||||||
|
(nlinum-relative-on)))
|
||||||
|
((not (null doom-line-numbers-style))
|
||||||
|
(nlinum-mode (or arg +1)))))
|
||||||
|
|
||||||
|
(defun doom|disable-line-numbers ()
|
||||||
|
"Disable the display of line numbers."
|
||||||
|
(doom|enable-line-numbers -1))
|
||||||
|
|
||||||
|
(add-hook! (prog-mode text-mode conf-mode)
|
||||||
|
#'(doom|enable-line-numbers hl-line-mode))
|
||||||
|
|
||||||
|
;; Emacs 26+ has native line number support.
|
||||||
|
(unless (boundp 'display-line-numbers)
|
||||||
|
;; Line number column. A faster (or equivalent, in the worst case) line number
|
||||||
|
;; plugin than `linum-mode'.
|
||||||
|
(def-package! nlinum
|
||||||
:commands nlinum-mode
|
:commands nlinum-mode
|
||||||
:init
|
:init
|
||||||
(defun doom|init-nlinum-mode ()
|
(defvar doom-line-number-lpad 4
|
||||||
"Turn on `nlinum-mode', except in org-mode"
|
"How much padding to place before line numbers.")
|
||||||
(unless (eq major-mode 'org-mode)
|
(defvar doom-line-number-rpad 1
|
||||||
(nlinum-mode +1)))
|
"How much padding to place after line numbers.")
|
||||||
(add-hook! (prog-mode text-mode) #'doom|init-nlinum-mode)
|
(defvar doom-line-number-pad-char 32
|
||||||
|
"Character to use for padding line numbers.
|
||||||
|
|
||||||
|
By default, this is a space character. If you use `whitespace-mode' with
|
||||||
|
`space-mark', the whitespace in line numbers will be affected (this can look
|
||||||
|
ugly). In this case, you can change this to ?\u2002, which is a unicode
|
||||||
|
character that looks like a space that `whitespace-mode' won't affect.")
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(setq nlinum-highlight-current-line t)
|
(setq nlinum-highlight-current-line t)
|
||||||
|
|
||||||
|
;; Fix lingering hl-line overlays (caused by nlinum)
|
||||||
|
(add-hook! 'hl-line-mode-hook
|
||||||
|
(remove-overlays (point-min) (point-max) 'face 'hl-line))
|
||||||
|
|
||||||
(defun doom-nlinum-format-fn (line _width)
|
(defun doom-nlinum-format-fn (line _width)
|
||||||
"A more customizable `nlinum-format-function'. See `doom-line-number-lpad',
|
"A more customizable `nlinum-format-function'. See `doom-line-number-lpad',
|
||||||
`doom-line-number-rpad' and `doom-line-number-pad-char'. Allows a fix for
|
`doom-line-number-rpad' and `doom-line-number-pad-char'. Allows a fix for
|
||||||
|
@ -364,9 +409,8 @@ local value, whether or not it's permanent-local. Therefore, we cycle
|
||||||
(format-mode-line "%l")))))
|
(format-mode-line "%l")))))
|
||||||
(add-hook 'nlinum-mode-hook #'doom|init-nlinum-width))
|
(add-hook 'nlinum-mode-hook #'doom|init-nlinum-width))
|
||||||
|
|
||||||
;; Fixes disappearing line numbers in nlinum and other quirks
|
;; Fixes disappearing line numbers in nlinum and other quirks
|
||||||
(def-package! nlinum-hl
|
(def-package! nlinum-hl
|
||||||
:unless (boundp 'display-line-numbers)
|
|
||||||
:after nlinum
|
:after nlinum
|
||||||
:config
|
:config
|
||||||
;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode',
|
;; With `markdown-fontify-code-blocks-natively' enabled in `markdown-mode',
|
||||||
|
@ -382,25 +426,11 @@ local value, whether or not it's permanent-local. Therefore, we cycle
|
||||||
;; forces them to resize.
|
;; forces them to resize.
|
||||||
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
|
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
|
||||||
|
|
||||||
;; Helps us distinguish stacked delimiter pairs. Especially in parentheses-drunk
|
(def-package! nlinum-relative
|
||||||
;; languages like Lisp.
|
:commands nlinum-relative-mode
|
||||||
(def-package! rainbow-delimiters
|
|
||||||
:commands rainbow-delimiters-mode
|
|
||||||
:config (setq rainbow-delimiters-max-face-count 3)
|
|
||||||
:init (add-hook 'lisp-mode-hook #'rainbow-delimiters-mode))
|
|
||||||
|
|
||||||
;; indicators for empty lines past EOF
|
|
||||||
(def-package! vi-tilde-fringe
|
|
||||||
:commands global-vi-tilde-fringe-mode
|
|
||||||
:init (add-hook 'doom-init-hook #'global-vi-tilde-fringe-mode))
|
|
||||||
|
|
||||||
;; For a distractions-free-like UI, that dynamically resizes margets and can
|
|
||||||
;; center a buffer.
|
|
||||||
(def-package! visual-fill-column
|
|
||||||
:commands visual-fill-column-mode
|
|
||||||
:config
|
:config
|
||||||
(setq-default visual-fill-column-center-text nil
|
(after! evil
|
||||||
visual-fill-column-width fill-column))
|
(nlinum-relative-setup-evil))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
(package! highlight-numbers)
|
(package! highlight-numbers)
|
||||||
(unless (boundp 'display-line-numbers)
|
(unless (boundp 'display-line-numbers)
|
||||||
(package! nlinum)
|
(package! nlinum)
|
||||||
(package! nlinum-hl))
|
(package! nlinum-hl)
|
||||||
|
(package! nlinum-relative))
|
||||||
(package! rainbow-delimiters)
|
(package! rainbow-delimiters)
|
||||||
(package! vi-tilde-fringe)
|
(package! vi-tilde-fringe)
|
||||||
(package! visual-fill-column)
|
(package! visual-fill-column)
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
(defun +org|hook ()
|
(defun +org|hook ()
|
||||||
"Run everytime `org-mode' is enabled."
|
"Run everytime `org-mode' is enabled."
|
||||||
(setq line-spacing 1)
|
(setq line-spacing 1)
|
||||||
|
(doom|disable-line-numbers)
|
||||||
|
|
||||||
;; show-paren-mode causes problems for org-indent-mode
|
;; show-paren-mode causes problems for org-indent-mode
|
||||||
(make-local-variable 'show-paren-mode)
|
(make-local-variable 'show-paren-mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue