Refactor doom/toggle-line-numbers; add doom-line-numbers-visual-style #376

doom-line-numbers-visual-style adds support for the visual
display-line-numbers mode by setting it to a non-nil value.
This commit is contained in:
Henrik Lissner 2018-01-30 03:27:38 -05:00
parent 64a674dcc9
commit bcef66b947
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 22 additions and 8 deletions

View file

@ -19,16 +19,17 @@ Cycles through regular, relative and no line numbers. The order depends on what
Uses `display-line-numbers' in Emacs 26+ and `nlinum-mode' everywhere else."
(interactive)
(let* ((order (pcase doom-line-numbers-style
(`relative '(relative t nil))
(`t '(t relative nil))
(`nil '(nil t relative))))
(let* ((styles '(t relative nil))
(order (cons doom-line-numbers-style (delq doom-line-numbers-style styles)))
(queue (memq doom--line-number-style order))
(next (if (= (length queue) 1)
(car order)
(car (cdr queue)))))
(setq doom--line-number-style next)
(cond ((boundp 'display-line-numbers)
(when (and (eq next 'relative)
doom-line-numbers-visual-style)
(setq next 'visual))
(setq display-line-numbers next))
((featurep 'nlinum)
(pcase next
@ -36,7 +37,13 @@ Uses `display-line-numbers' in Emacs 26+ and `nlinum-mode' everywhere else."
(`relative (nlinum-relative-on))
(`nil (nlinum-mode -1))))
(t
(error "No line number plugin detected")))))
(error "No line number plugin detected")))
(message "Switched to %s line numbers"
(pcase next
(`t "normal")
(`relative "relative")
(`visual "visual")
(`nil "disabled")))))
;;;###autoload
(defun doom-resize-window (window new-size &optional horizontal force-p)

View file

@ -319,9 +319,8 @@ DEFAULT is non-nil, set the default mode-line for all buffers."
;;
(defvar doom-line-numbers-style t
"The default styles to use for the line number display.
Takes the same argument as `display-line-numbers' in Emacs 26, which are:
"The default styles to use for the line number display. Accepts one of the
following:
nil No line numbers
t Ordinary line numbers
@ -329,6 +328,14 @@ Takes the same argument as `display-line-numbers' in Emacs 26, which are:
Use `doom/toggle-line-numbers' to cycle between these line number styles.")
(when (boundp 'display-line-numbers)
(defvar doom-line-numbers-visual-style nil
"If non-nil, relative line numbers will be countered by screen line, rather
than buffer line. Setting this to non-nil is the equivalent of using 'visual in
`display-line-numbers'.
It has no effect on nlinum."))
(defun doom|enable-line-numbers (&optional arg)
"Enables the display of line numbers, using `display-line-numbers' (in Emacs
26+) or `nlinum-mode'.