Use global-hl-line-mode instead of hl-line

It's easier for users to remove one hook than to remove four, and Emacs
users tend to expect global-hl-line-mode, but not hl-line-mode.
This commit is contained in:
Henrik Lissner 2020-11-14 13:56:14 -05:00
parent f40a2e1ed7
commit 472ec52481
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -391,8 +391,24 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(use-package! hl-line
;; Highlights the current line
:hook ((prog-mode text-mode conf-mode special-mode) . hl-line-mode)
:hook (doom-first-buffer . global-hl-line-mode)
:init
(defvar global-hl-line-modes '(prog-mode text-mode conf-mode special-mode)
"What modes to enable `hl-line-mode' in.")
:config
;; HACK I reimplement `global-hl-line-mode' so we can white/blacklist modes in
;; `global-hl-line-modes' _and_ so we can use `global-hl-line-mode',
;; which users expect to control hl-line in Emacs.
(define-globalized-minor-mode global-hl-line-mode hl-line-mode
(lambda ()
(and (not hl-line-mode)
(cond ((null global-hl-line-modes) nil)
((eq global-hl-line-modes t))
((eq (car global-hl-line-modes) 'not)
(not (derived-mode-p global-hl-line-modes)))
((apply #'derived-mode-p global-hl-line-modes)))
(hl-line-mode +1))))
;; Not having to render the hl-line overlay in multiple buffers offers a tiny
;; performance boost. I also don't need to see it in other buffers.
(setq hl-line-sticky-flag nil