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))
(order (cons display-line-numbers-type (remq display-line-numbers-type styles)))
(queue (memq doom--line-number-style order)) (queue (memq doom--line-number-style order))
(next (if (= (length queue) 1) (next (if (= (length queue) 1)
(car order) (car order)
(car (cdr queue))))) (car (cdr queue)))))
(setq doom--line-number-style next) (setq doom--line-number-style next)
(cond ((boundp 'display-line-numbers) (if (get 'display-line-numbers 'nlinum)
(when (and (eq next 'relative)
doom-line-numbers-visual-style)
(setq next 'visual))
(setq display-line-numbers next))
((featurep 'nlinum)
(pcase next (pcase next
(`t (nlinum-relative-off) (nlinum-mode +1)) (`t (nlinum-relative-off) (nlinum-mode +1))
(`relative (nlinum-relative-on)) (`relative (nlinum-relative-on))
(`nil (nlinum-mode -1)))) (`nil (nlinum-mode -1)))
(t (setq display-line-numbers next))
(error "No line number plugin detected")))
(message "Switched to %s line numbers" (message "Switched to %s line numbers"
(pcase next (pcase next
(`t "normal") (`t "normal")
(`relative "relative") (`nil "disabled")
(`visual "visual") (x (symbol-name next)))))))
(`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)