Update doom/toggle-line-numbers #847

Now that display-line-numbers-mode has been backported to Emacs 25, we
can use it instead of interacting with nlinum directly.
This commit is contained in:
Henrik Lissner 2018-08-29 01:11:50 +02:00
parent a57c0fbede
commit d6695d4cf3
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -5,36 +5,31 @@
"Toggle line numbers. "Toggle line numbers.
Cycles through regular, relative and no line numbers. The order depends on what Cycles through regular, relative and no line numbers. The order depends on what
`doom-line-numbers-style' is set to. `display-line-numbers-type' is set to. If you're using Emacs 26+, and
visual-line-mode is on, this skips relative and uses visual instead.
Uses `display-line-numbers' in Emacs 26+ and `nlinum-mode' everywhere else." See `display-line-numbers' for what these values mean."
(interactive) (interactive)
(defvar doom--line-number-style doom-line-numbers-style) (defvar doom--line-number-style display-line-numbers-type)
(let* ((styles '(t relative nil)) (let ((nlinum-p (get 'display-line-numbers 'nlinum)))
(order (cons doom-line-numbers-style (delq doom-line-numbers-style styles))) (let* ((styles `(t ,(if (and (not nlinum-p) visual-line-mode) 'visual 'relative) nil))
(queue (memq doom--line-number-style order)) (order (cons display-line-numbers-type (remq display-line-numbers-type styles)))
(next (if (= (length queue) 1) (queue (memq doom--line-number-style order))
(car order) (next (if (= (length queue) 1)
(car (cdr queue))))) (car order)
(setq doom--line-number-style next) (car (cdr queue)))))
(cond ((boundp 'display-line-numbers) (setq doom--line-number-style next)
(when (and (eq next 'relative) (if (get 'display-line-numbers 'nlinum)
doom-line-numbers-visual-style) (pcase next
(setq next 'visual)) (`t (nlinum-relative-off) (nlinum-mode +1))
(setq display-line-numbers next)) (`relative (nlinum-relative-on))
((featurep 'nlinum) (`nil (nlinum-mode -1)))
(pcase next (setq display-line-numbers next))
(`t (nlinum-relative-off) (nlinum-mode +1)) (message "Switched to %s line numbers"
(`relative (nlinum-relative-on)) (pcase next
(`nil (nlinum-mode -1)))) (`t "normal")
(t (`nil "disabled")
(error "No line number plugin detected"))) (x (symbol-name next)))))))
(message "Switched to %s line numbers"
(pcase next
(`t "normal")
(`relative "relative")
(`visual "visual")
(`nil "disabled")))))
;;;###autoload ;;;###autoload
(defun doom-resize-window (window new-size &optional horizontal force-p) (defun doom-resize-window (window new-size &optional horizontal force-p)