Use EMACS26+ to detect native line numbers

Checking for the 'display-line-numbers symbol property is clumsy and
checking for boundp is pointless now that we have a Emacs 25 polyfill
for display-line-numbers-mode.
This commit is contained in:
Henrik Lissner 2018-09-07 20:08:06 -04:00
parent be29623f0d
commit 49e6e68a07
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 31 additions and 37 deletions

View file

@ -62,25 +62,24 @@ visual-line-mode is on, this skips relative and uses visual instead.
See `display-line-numbers' for what these values mean."
(interactive)
(defvar doom--line-number-style display-line-numbers-type)
(let ((nlinum-p (get 'display-line-numbers 'nlinum)))
(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))
(next (if (= (length queue) 1)
(car order)
(car (cdr queue)))))
(setq doom--line-number-style next)
(if (get 'display-line-numbers 'nlinum)
(pcase next
(`t (nlinum-relative-off) (nlinum-mode +1))
(`relative (nlinum-relative-on))
(`nil (nlinum-mode -1)))
(setq display-line-numbers next))
(message "Switched to %s line numbers"
(pcase next
(`t "normal")
(`nil "disabled")
(x (symbol-name next)))))))
(let* ((styles `(t ,(if (and EMACS26+ 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))
(next (if (= (length queue) 1)
(car order)
(car (cdr queue)))))
(setq doom--line-number-style next)
(if EMACS26+
(setq display-line-numbers next)
(pcase next
(`t (nlinum-relative-off) (nlinum-mode +1))
(`relative (nlinum-relative-on))
(`nil (nlinum-mode -1))))
(message "Switched to %s line numbers"
(pcase next
(`t "normal")
(`nil "disabled")
(_ (symbol-name next))))))
;;;###autoload
(defun doom/reload-theme ()