From 14ea4b0b89c6f871e3956102d51f17b055c8af69 Mon Sep 17 00:00:00 2001 From: Luigi Sartor Piucco Date: Fri, 27 Oct 2023 16:09:14 -0300 Subject: [PATCH] tweak(corfu): place extra CAPFs behind flags --- modules/completion/corfu/README.org | 14 +++++-- modules/completion/corfu/config.el | 65 ++++++++++++++++------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index a72f336bc..224d6959c 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -20,12 +20,20 @@ highly non-native, but has some extra features and more maturity. - +icons :: Display icons beside completion suggestions. - +tng :: - Invoke completion on [[kbd:][TAB]]. When corfu is active, [[kbd:][TAB]] and [[kbd:][S-TAB]] will navigate - the completion candidates. Arrow keys and evil-style movement are still - supported. + Invoke completion on [[kbd:][TAB]]. When corfu is active, [[kbd:][TAB]] and + [[kbd:][S-TAB]] will navigate the completion candidates. Arrow keys and + evil-style movement are still supported. - +orderless :: Pull in [[doom-package:orderless]] if necessary and apply multi-component completion (still needed if [[doom-module::completion vertico]] is active). +- +dabbrev :: + Enable and configure [[doom-package:dabbrev]] as a nigh on everywhere CAPF + fallback. +- +dict :: + Enable and configure dictionary completion for text modes and related regions + in programming modes. +- +emoji :: + Enable and configure emoji completion via the emoji input method. ** Packages - [[doom-package:corfu]] diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 6bcc6ac38..632b61364 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -178,35 +178,39 @@ This variable needs to be set at the top-level before any `after!' blocks.") (use-package! cape :defer t :init - ;; Set up `cape-dabbrev' and `cape-line' options. - (defun +cape-line-buffers () - (cl-loop for buf in (buffer-list) - if (or (eq major-mode (buffer-local-value 'major-mode buf)) - (< (buffer-size buf) +cape-buffer-scanning-size-limit)) - collect buf)) - (defun +dabbrev-friend-buffer-p (other-buffer) - (< (buffer-size other-buffer) +cape-buffer-scanning-size-limit)) - (setq cape-dabbrev-check-other-buffers t - cape-line-buffer-function #'+cape-line-buffers - dabbrev-friend-buffer-function #'+dabbrev-friend-buffer-p - dabbrev-ignored-buffer-regexps - '("\\.\\(?:pdf\\|jpe?g\\|png\\|svg\\|eps\\)\\'" - "^ " - "\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?") - dabbrev-upcase-means-case-search t) - (add-hook! prog-mode (add-hook 'completion-at-point-functions #'cape-file -10 t)) (add-hook! (org-mode markdown-mode) (add-hook 'completion-at-point-functions #'cape-elisp-block 0 t)) ;; Enable Dabbrev completion basically everywhere as a fallback. - (add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup - eshell-mode) - (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t)) + (when (modulep! +dabbrev) + ;; Set up `cape-dabbrev' options. + (defun +dabbrev-friend-buffer-p (other-buffer) + (< (buffer-size other-buffer) +cape-buffer-scanning-size-limit)) + (setq cape-dabbrev-check-other-buffers t + dabbrev-friend-buffer-function #'+dabbrev-friend-buffer-p + dabbrev-ignored-buffer-regexps + '("\\.\\(?:pdf\\|jpe?g\\|png\\|svg\\|eps\\)\\'" + "^ " + "\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?") + dabbrev-upcase-means-case-search t) + (add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup + eshell-mode) + (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t))) + (when (modulep! +line) + ;; Set up `cape-line' options. + (defun +cape-line-buffers () + (cl-loop for buf in (buffer-list) + if (or (eq major-mode (buffer-local-value 'major-mode buf)) + (< (buffer-size buf) +cape-buffer-scanning-size-limit)) + collect buf)) + (setq cape-line-buffer-function #'+cape-line-buffers) + (add-hook! (text-mode comint-mode minibuffer-setup) + (add-hook 'completion-at-point-functions #'cape-line 20 t))) ;; Complete emojis :). - (when (> emacs-major-version 28) + (when (and (modulep! +emoji) (> emacs-major-version 28)) (add-hook! (prog-mode conf-mode) (add-hook 'completion-at-point-functions (cape-capf-inside-faces @@ -220,15 +224,16 @@ This variable needs to be set at the top-level before any `after!' blocks.") (cape-capf-prefix-length #'cape-emoji 1) 10 t))) ;; Enable dictionary-based autocompletion. - (add-hook! text-mode - (add-hook 'completion-at-point-functions #'cape-dict 40 t)) - (add-hook! (prog-mode conf-mode) - (add-hook 'completion-at-point-functions - (cape-capf-inside-faces - ;; Only call inside comments and docstrings. - #'cape-dict 'tree-sitter-hl-face:doc 'font-lock-doc-face - 'font-lock-comment-face 'tree-sitter-hl-face:comment) - 40 t)) + (when (modulep! +dict) + (add-hook! text-mode + (add-hook 'completion-at-point-functions #'cape-dict 40 t)) + (add-hook! (prog-mode conf-mode) + (add-hook 'completion-at-point-functions + (cape-capf-inside-faces + ;; Only call inside comments and docstrings. + #'cape-dict 'tree-sitter-hl-face:doc 'font-lock-doc-face + 'font-lock-comment-face 'tree-sitter-hl-face:comment) + 40 t))) ;; Make these capfs composable. (advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)