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:
parent
be29623f0d
commit
49e6e68a07
3 changed files with 31 additions and 37 deletions
|
@ -1,5 +1,5 @@
|
||||||
;;; core/autoload/line-numbers.el -*- lexical-binding: t; -*-
|
;;; core/autoload/line-numbers.el -*- lexical-binding: t; -*-
|
||||||
;;;###if (not (locate-library "display-line-numbers"))
|
;;;###if (not EMACS26+)
|
||||||
|
|
||||||
;; This was lifted out of the display-line-numbers library in Emacs 26.1 and
|
;; This was lifted out of the display-line-numbers library in Emacs 26.1 and
|
||||||
;; modified to use nlinum for Emacs 25.x users. It should be removed should
|
;; modified to use nlinum for Emacs 25.x users. It should be removed should
|
||||||
|
@ -26,8 +26,6 @@ relative number of a line.
|
||||||
Lisp programs can disable display of a line number of a particular
|
Lisp programs can disable display of a line number of a particular
|
||||||
buffer line by putting the display-line-numbers-disable text property
|
buffer line by putting the display-line-numbers-disable text property
|
||||||
or overlay property on the first visible character of that line.")
|
or overlay property on the first visible character of that line.")
|
||||||
;;;###autoload
|
|
||||||
(put 'display-line-numbers 'nlinum t)
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defcustom display-line-numbers-type t
|
(defcustom display-line-numbers-type t
|
||||||
|
|
|
@ -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."
|
See `display-line-numbers' for what these values mean."
|
||||||
(interactive)
|
(interactive)
|
||||||
(defvar doom--line-number-style display-line-numbers-type)
|
(defvar doom--line-number-style display-line-numbers-type)
|
||||||
(let ((nlinum-p (get 'display-line-numbers 'nlinum)))
|
(let* ((styles `(t ,(if (and EMACS26+ visual-line-mode) 'visual 'relative) nil))
|
||||||
(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)))
|
||||||
(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)
|
(if EMACS26+
|
||||||
(if (get 'display-line-numbers 'nlinum)
|
(setq display-line-numbers next)
|
||||||
(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))))
|
||||||
(setq display-line-numbers next))
|
(message "Switched to %s line numbers"
|
||||||
(message "Switched to %s line numbers"
|
(pcase next
|
||||||
(pcase next
|
(`t "normal")
|
||||||
(`t "normal")
|
(`nil "disabled")
|
||||||
(`nil "disabled")
|
(_ (symbol-name next))))))
|
||||||
(x (symbol-name next)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/reload-theme ()
|
(defun doom/reload-theme ()
|
||||||
|
|
|
@ -121,8 +121,7 @@ shorter major mode name in the mode-line. See `doom|set-mode-name'.")
|
||||||
(setq visual-fill-column-center-text t
|
(setq visual-fill-column-center-text t
|
||||||
visual-fill-column-width
|
visual-fill-column-width
|
||||||
;; take Emacs 26 line numbers into account
|
;; take Emacs 26 line numbers into account
|
||||||
(+ (if (boundp 'display-line-numbers) 6 0)
|
(+ (if EMACS26+ 6 0) fill-column))
|
||||||
fill-column))
|
|
||||||
|
|
||||||
(defun doom*hide-undefined-which-key-binds (bindings)
|
(defun doom*hide-undefined-which-key-binds (bindings)
|
||||||
(cl-loop for bind in bindings
|
(cl-loop for bind in bindings
|
||||||
|
@ -242,18 +241,20 @@ shorter major mode name in the mode-line. See `doom|set-mode-name'.")
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Line numbers
|
;; Line numbers
|
||||||
;;
|
|
||||||
|
;; line numbers in most modes
|
||||||
|
(add-hook! (prog-mode text-mode conf-mode) #'display-line-numbers-mode)
|
||||||
|
|
||||||
;; Emacs 26+ has native line number support, and will ignore nlinum. This is for
|
;; Emacs 26+ has native line number support, and will ignore nlinum. This is for
|
||||||
;; Emacs 25 users:
|
;; Emacs 25 users:
|
||||||
(defun doom|enable-line-numbers () (display-line-numbers-mode +1))
|
(defun doom|enable-line-numbers () (display-line-numbers-mode +1))
|
||||||
(defun doom|disable-line-numbers () (display-line-numbers-mode -1))
|
(defun doom|disable-line-numbers () (display-line-numbers-mode -1))
|
||||||
|
|
||||||
;; Line number column. A faster (or equivalent, in the worst case) line number
|
|
||||||
;; plugin than `linum-mode'.
|
|
||||||
(def-package! nlinum
|
(def-package! nlinum
|
||||||
:when (get 'display-line-numbers 'nlinum)
|
;; Line number column. A faster (or equivalent, in the worst case) line number
|
||||||
:commands nlinum-mode
|
;; plugin than `linum-mode'.
|
||||||
|
:unless EMACS26+
|
||||||
|
:defer t
|
||||||
:init
|
:init
|
||||||
(defvar doom-line-number-lpad 4
|
(defvar doom-line-number-lpad 4
|
||||||
"How much padding to place before line numbers.")
|
"How much padding to place before line numbers.")
|
||||||
|
@ -298,9 +299,9 @@ character that looks like a space that `whitespace-mode' won't affect.")
|
||||||
(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
|
|
||||||
(def-package! nlinum-hl
|
(def-package! nlinum-hl
|
||||||
:when (get 'display-line-numbers 'nlinum)
|
;; Fixes disappearing line numbers in nlinum and other quirks
|
||||||
|
:unless EMACS26+
|
||||||
: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',
|
||||||
|
@ -315,8 +316,8 @@ character that looks like a space that `whitespace-mode' won't affect.")
|
||||||
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
|
(advice-add #'set-frame-font :after #'nlinum-hl-flush-all-windows))
|
||||||
|
|
||||||
(def-package! nlinum-relative
|
(def-package! nlinum-relative
|
||||||
:when (get 'display-line-numbers 'nlinum)
|
:unless EMACS26+
|
||||||
:commands (nlinum-relative-mode nlinum-relative-on nlinum-relative-off)
|
:defer t
|
||||||
:config
|
:config
|
||||||
(setq nlinum-format " %d ")
|
(setq nlinum-format " %d ")
|
||||||
(add-hook 'evil-mode #'nlinum-relative-setup-evil))
|
(add-hook 'evil-mode #'nlinum-relative-setup-evil))
|
||||||
|
@ -399,10 +400,6 @@ frame's window-system, the theme will be reloaded.")
|
||||||
|
|
||||||
;; a good indicator that Emacs isn't frozen
|
;; a good indicator that Emacs isn't frozen
|
||||||
(add-hook 'doom-init-ui-hook #'blink-cursor-mode)
|
(add-hook 'doom-init-ui-hook #'blink-cursor-mode)
|
||||||
|
|
||||||
;; line numbers in most modes
|
|
||||||
(add-hook! (prog-mode text-mode conf-mode) #'display-line-numbers-mode)
|
|
||||||
|
|
||||||
;; Make `next-buffer', `other-buffer', etc. ignore unreal buffers.
|
;; Make `next-buffer', `other-buffer', etc. ignore unreal buffers.
|
||||||
(add-to-list 'default-frame-alist (cons 'buffer-predicate #'doom-buffer-frame-predicate))
|
(add-to-list 'default-frame-alist (cons 'buffer-predicate #'doom-buffer-frame-predicate))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue