Properly lazy load flyspell

Package was eagerly loaded at startup, so we must pretend it hasn't to
defer it and future configuration.

And generalize defer-feature! macro.
This commit is contained in:
Henrik Lissner 2020-06-05 01:41:49 -04:00
parent 85883facf5
commit 5b8b04f0c8
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395
2 changed files with 21 additions and 9 deletions

View File

@ -424,7 +424,7 @@ serve as a predicated alternative to `after!'."
(put ',fn 'permanent-local-hook t)
(add-hook 'after-load-functions #',fn)))))
(defmacro defer-feature! (feature &optional fn)
(defmacro defer-feature! (feature &rest fns)
"Pretend FEATURE hasn't been loaded yet, until FEATURE-hook or FN runs.
Some packages (like `elisp-mode' and `lisp-mode') are loaded immediately at
@ -432,21 +432,20 @@ startup, which will prematurely trigger `after!' (and `with-eval-after-load')
blocks. To get around this we make Emacs believe FEATURE hasn't been loaded yet,
then wait until FEATURE-hook (or MODE-hook, if FN is provided) is triggered to
reverse this and trigger `after!' blocks at a more reasonable time."
(let ((advice-fn (intern (format "doom--defer-feature-%s-a" feature)))
(fn (or fn feature)))
(let ((advice-fn (intern (format "doom--defer-feature-%s-a" feature))))
`(progn
(setq features (delq ',feature features))
(advice-add #',fn :before #',advice-fn)
(defun ,advice-fn (&rest _)
(delq! ',feature features)
(defadvice! ,advice-fn (&rest _)
:before ',fns
;; Some plugins (like yasnippet) will invoke a fn early to parse
;; code, which would prematurely trigger this. In those cases, well
;; behaved plugins will use `delay-mode-hooks', which we can check for:
(when (and ,(intern (format "%s-hook" fn))
(not delay-mode-hooks))
(unless delay-mode-hooks
;; ...Otherwise, announce to the world this package has been loaded,
;; so `after!' handlers can react.
(provide ',feature)
(advice-remove #',fn #',advice-fn))))))
(dolist (fn ',fns)
(advice-remove fn #',advice-fn)))))))
;;; Hooks

View File

@ -46,6 +46,13 @@
;; messages for every word when checking the entire buffer
flyspell-issue-message-flag nil)
(use-package! flyspell ; built-in
:defer t
:preface
;; `flyspell' is loaded at startup. In order to lazy load its config we need
;; to pretend it isn't loaded.
(defer-feature! flyspell flyspell-mode flyspell-prog-mode)
:init
(add-hook! '(org-mode-hook
markdown-mode-hook
TeX-mode-hook
@ -61,6 +68,12 @@
prog-mode-hook)
#'flyspell-prog-mode))
:config
(setq flyspell-issue-welcome-flag nil
;; Significantly speeds up flyspell, which would otherwise print
;; messages for every word when checking the entire buffer
flyspell-issue-message-flag nil)
(add-hook! 'flyspell-mode-hook
(defun +spell-inhibit-duplicate-detection-maybe-h ()
"Don't mark duplicates when style/grammar linters are present.