From 86e5994003470dc5dfd46d477a714c714f664cc0 Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:44:00 -0600 Subject: [PATCH 1/6] fix(corfu): load minibuffer-setup-hook earlier This way Corfu can be lazily-loaded by the minibuffer-setup-hook. --- modules/completion/corfu/config.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 41e54d945..c3190fe71 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -7,6 +7,13 @@ ;;; Packages (use-package! corfu :hook (doom-first-input . global-corfu-mode) + :init + (add-hook! 'minibuffer-setup-hook + (defun +corfu-enable-in-minibuffer () + "Enable Corfu in the minibuffer if `completion-at-point' is bound." + (when (where-is-internal #'completion-at-point (list (current-local-map))) + (setq-local corfu-echo-delay nil) + (corfu-mode +1)))) :config (setq corfu-auto t corfu-auto-delay 0.1 @@ -34,12 +41,6 @@ (add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer) - (add-hook! 'minibuffer-setup-hook - (defun +corfu-enable-in-minibuffer () - "Enable Corfu in the minibuffer if `completion-at-point' is bound." - (when (where-is-internal #'completion-at-point (list (current-local-map))) - (setq-local corfu-echo-delay nil) - (corfu-mode +1)))) (after! evil (add-hook 'evil-insert-state-exit-hook #'corfu-quit)) From 775749c4cff8075c80364126fe18dfe354ab730b Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:45:49 -0600 Subject: [PATCH 2/6] refactor(corfu): unwrap add-hook from after! block add-hook handles void variables so there is no need to wrap it in an after! block. This also makes it easier for the user to remove the hook. --- modules/completion/corfu/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index c3190fe71..b59d5e2fe 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -42,8 +42,7 @@ (add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer) - (after! evil - (add-hook 'evil-insert-state-exit-hook #'corfu-quit)) + (add-hook 'evil-insert-state-exit-hook #'corfu-quit) (when (modulep! +icons) (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)) From b2c1b574e26425f97b1425d2edb695e3af362a53 Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:47:35 -0600 Subject: [PATCH 3/6] feat(corfu): update minibuffer hints manually In the scenario where we exit the minibuffer using C-RET or S-RET, we need this advice to ensure that visual hints are updated before exiting. --- modules/completion/corfu/config.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index b59d5e2fe..ab17c7dbb 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -49,7 +49,26 @@ (when (modulep! +orderless) (after! orderless - (setq orderless-component-separator #'orderless-escapable-split-on-space)))) + (setq orderless-component-separator #'orderless-escapable-split-on-space))) + + ;; If you want to update the visual hints after completing minibuffer commands + ;; with Corfu and exiting, you have to do it manually. + (defadvice! +corfu--insert-before-exit-minibuffer-a () + :before #'exit-minibuffer + (when (or (and (frame-live-p corfu--frame) + (frame-visible-p corfu--frame)) + (and (featurep 'corfu-terminal) + (popon-live-p corfu-terminal--popon))) + (when (member isearch-lazy-highlight-timer timer-idle-list) + (apply (timer--function isearch-lazy-highlight-timer) + (timer--args isearch-lazy-highlight-timer))) + (when (member (bound-and-true-p anzu--update-timer) timer-idle-list) + (apply (timer--function anzu--update-timer) + (timer--args anzu--update-timer))) + (when (member (bound-and-true-p evil--ex-search-update-timer) + timer-idle-list) + (apply (timer--function evil--ex-search-update-timer) + (timer--args evil--ex-search-update-timer)))))) (use-package! cape :defer t From 3b275b271ac3ff52cc5baaf9b8e8f137c6e889ea Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:50:17 -0600 Subject: [PATCH 4/6] fix(corfu): bind cape-dabbrev eagerly Set up cape-dabbrev in completion-at-point-functions before dabbrev is loaded. --- modules/completion/corfu/config.el | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index ab17c7dbb..94c992045 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -84,6 +84,10 @@ ;; Set up `cape-dabbrev' options. (defun +dabbrev-friend-buffer-p (other-buffer) (< (buffer-size other-buffer) +corfu-buffer-scanning-size-limit)) + (add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup + eshell-mode) + (defun +corfu-add-cape-dabbrev-h () + (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t))) (after! dabbrev (setq cape-dabbrev-check-other-buffers t dabbrev-friend-buffer-function #'+dabbrev-friend-buffer-p @@ -91,12 +95,7 @@ '("^ " "\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?") dabbrev-upcase-means-case-search t) - (add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode) - - (add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup - eshell-mode) - (defun +corfu-add-cape-dabbrev-h () - (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t))))) + (add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode))) ;; Complete emojis :). (when (and (modulep! +emoji) (> emacs-major-version 28)) (add-hook! (prog-mode conf-mode) From 39b0de8736ef9d1e6995fb28d1ddffae2a2448da Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:52:57 -0600 Subject: [PATCH 5/6] feat(config): make C-x corfu bindings optional For someone like me that uses the vanilla emacs commands bound to C-x C-p, C-x C-n, etc, I prefer to set the completion keybindings manually. --- modules/completion/corfu/config.el | 3 +++ modules/config/default/+evil-bindings.el | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 94c992045..e8805ce2b 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -3,6 +3,9 @@ (defvar +corfu-buffer-scanning-size-limit (* 1 1024 1024) ; 1 MB "Size limit for a buffer to be scanned by `cape-dabbrev'.") +(defvar +corfu-want-C-x-bindings t + "Whether `C-x' is a completion prefix in Evil insert state.") + ;; ;;; Packages (use-package! corfu diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index c935ac948..741083f63 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -163,14 +163,15 @@ (:after corfu (:map corfu-mode-map :e "C-M-i" #'completion-at-point - (:prefix "C-x" - :i "C-l" #'cape-line - :i "C-k" #'cape-keyword - :i "C-f" #'cape-file - :i "s" #'cape-dict - :i "C-s" #'yasnippet-capf - :i "C-n" #'cape-dabbrev - :i "C-p" #'cape-history) + (:when +corfu-want-C-x-bindings + (:prefix "C-x" + :i "C-l" #'cape-line + :i "C-k" #'cape-keyword + :i "C-f" #'cape-file + :i "s" #'cape-dict + :i "C-s" #'yasnippet-capf + :i "C-n" #'cape-dabbrev + :i "C-p" #'cape-history)) (:unless (modulep! :completion corfu +tng) :i "C-SPC" #'completion-at-point :n "C-SPC" (cmd! (call-interactively #'evil-insert-state) From 3cc46059434ba3027d8a7f7e5cb50b50ff8aea5b Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Sat, 17 Feb 2024 10:55:19 -0600 Subject: [PATCH 6/6] fix(corfu): bind tng tab commands to insert state These commands were being shadowed by the other Corfu commands previously. --- modules/config/default/config.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/config/default/config.el b/modules/config/default/config.el index 1108190f9..81203f6ea 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -469,10 +469,10 @@ Continues comments if executed from a commented line. Consults (:when (modulep! :completion corfu +orderless) [remap completion-at-point] #'+corfu-smart-sep-toggle-escape) (:when (modulep! :completion corfu +tng) - [tab] #'corfu-next - "TAB" #'corfu-next - [backtab] #'corfu-previous - "S-TAB" #'corfu-previous)) + :gi [tab] #'corfu-next + :gi "TAB" #'corfu-next + :gi [backtab] #'corfu-previous + :gi "S-TAB" #'corfu-previous)) (:after corfu-popupinfo :map corfu-popupinfo-map "C-" #'corfu-popupinfo-scroll-down