From 2d62db15c4ec78842303c23f824be57a1daf98e4 Mon Sep 17 00:00:00 2001 From: Liam Hupfer Date: Sun, 24 Sep 2023 15:28:45 -0500 Subject: [PATCH] perf(corfu): improve lazy loading `:after y` eagerly loads package x after y loads. Cape and `yasnippet-capf` define autoloads, so we can defer them until a capf is actually called. --- modules/completion/corfu/config.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 150047911..6833afb56 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -61,7 +61,7 @@ must be present.") :hook (org-mode . corfu-mode) :init ;; Auto-completion settings, must be set before calling `global-corfu-mode'. - ;; Due to lazy-loading, setting them in config.el works too. + ;; Due to lazy-loading, overriding these in config.el works too. (setq corfu-auto t corfu-auto-delay 0.1 corfu-auto-prefix 2 @@ -154,17 +154,19 @@ Meant as :around advice for `corfu--recompute'." (:when (modulep! :editor evil) "s-j" #'corfu-move-to-minibuffer)))) (use-package! cape - :after corfu - :config + :defer t + :init (add-hook! prog-mode (add-to-list 'completion-at-point-functions #'cape-file)) (add-hook! (org-mode markdown-mode) (add-to-list 'completion-at-point-functions #'cape-elisp-block)) (advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible)) (use-package! yasnippet-capf - :after corfu - :config - (add-hook 'yas-minor-mode-hook - (lambda () (add-to-list 'completion-at-point-functions #'yasnippet-capf)))) + :when (modulep! :editor snippets) + :defer t + :init + (after! yasnippet + (add-hook! yas-minor-mode + (add-to-list 'completion-at-point-functions #'yasnippet-capf)))) (use-package! corfu-terminal :when (not (display-graphic-p))