updated corfu module from latest pr

This commit is contained in:
Matt Nish-Lapidus 2023-10-31 11:50:28 -04:00
parent 2fd726f5e2
commit e4f80a2bc7
7 changed files with 313 additions and 185 deletions

View file

@ -23,7 +23,7 @@
(map! :leader (map! :leader
"`" nil "`" nil
(:prefix ("l" . "<localleader>")) ; bound locally (:prefix ("m" . "<localleader>")) ; bound locally
(:prefix-map ("!" . "checkers")) ; bound by flycheck (:prefix-map ("!" . "checkers")) ; bound by flycheck
:desc "M-x" ":" #'execute-extended-command :desc "M-x" ":" #'execute-extended-command

View file

@ -41,11 +41,6 @@
(call-interactively #'consult-yasnippet)) (call-interactively #'consult-yasnippet))
(t (call-interactively #'yas-insert-snippet)))) (t (call-interactively #'yas-insert-snippet))))
(use-package! yasnippet-capf
:after cape
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf))
;; set default frame size on launch ;; set default frame size on launch
(setq default-frame-alist '( (left . 0) (top . 0) (height . 48) (width . 160) )) (setq default-frame-alist '( (left . 0) (top . 0) (height . 48) (width . 160) ))
@ -130,7 +125,6 @@
(add-to-list 'auto-mode-alist '("\\.svelte\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.svelte\\'" . web-mode))
(setq web-mode-engines-alist (setq web-mode-engines-alist
'(("svelte" . "\\.svelte\\'"))) '(("svelte" . "\\.svelte\\'")))
(add-hook! web-mode (web-mode-use-tabs) (setq indent-tabs-mode t))
(add-hook! web-mode (web-mode-toggle-current-element-highlight)) (add-hook! web-mode (web-mode-toggle-current-element-highlight))
;; fix centaur tabs to show at the right times and add my muscle memory keybind ;; fix centaur tabs to show at the right times and add my muscle memory keybind

View file

@ -31,6 +31,7 @@ highly non-native, but has some extra features and more maturity.
- [[doom-package:corfu]] - [[doom-package:corfu]]
- [[doom-package:cape]] - [[doom-package:cape]]
- [[doom-package:nerd-icons-completion]] if [[doom-module::completion corfu +icons]] - [[doom-package:nerd-icons-completion]] if [[doom-module::completion corfu +icons]]
- [[doom-package:nerd-icons-corfu]] if [[doom-module::completion corfu +icons]]
- [[doom-package:orderless]] if [[doom-module::completion corfu +orderless]] - [[doom-package:orderless]] if [[doom-module::completion corfu +orderless]]
- [[doom-package:corfu-terminal]] if [[doom-module::os tty]] - [[doom-package:corfu-terminal]] if [[doom-module::os tty]]
- [[doom-package:yasnippet-capf]] if [[doom-module::editor snippets]] - [[doom-package:yasnippet-capf]] if [[doom-module::editor snippets]]
@ -64,7 +65,7 @@ characters, or by means of the [[kbd:][C-SPC]] keybinding at any moment. While t
is visible, the following relevant keys are available: is visible, the following relevant keys are available:
| Keybind | Description | | Keybind | Description |
|----------+------------------------------------------------------| |----------+---------------------------------------------------------|
| [[kbd:][<down>]] | Go to next candidate | | [[kbd:][<down>]] | Go to next candidate |
| [[kbd:][<up>]] | Go to previous candidate | | [[kbd:][<up>]] | Go to previous candidate |
| [[kbd:][C-n]] | Go to next candidate | | [[kbd:][C-n]] | Go to next candidate |
@ -78,9 +79,10 @@ is visible, the following relevant keys are available:
| [[kbd:][C-S-j]] | (evil) Go to next doc line | | [[kbd:][C-S-j]] | (evil) Go to next doc line |
| [[kbd:][C-S-k]] | (evil) Go to previous doc line | | [[kbd:][C-S-k]] | (evil) Go to previous doc line |
| [[kbd:][C-h]] | Toggle documentation (if available) | | [[kbd:][C-h]] | Toggle documentation (if available) |
| [[kbd:][s-<down>]] | Export to minibuffer (if [[doom-module::completion vertico]]) | | [[kbd:][M-m]] | Export to minibuffer (if [[doom-module::completion vertico]]) |
| [[kbd:][s-j]] | (evil) Export to minibuffer (if [[doom-module::completion vertico]]) | | [[kbd:][M-j]] | (evil) Export to minibuffer (if [[doom-module::completion vertico]]) |
| [[kbd:][RET]] | Insert candidate | | [[kbd:][RET]] | Insert candidate |
| [[kbd:][SPC]] | Quit autocompletion after a wildcard or pass-through |
| [[kbd:][C-SPC]] | (when completing) Insert separator (see below) | | [[kbd:][C-SPC]] | (when completing) Insert separator (see below) |
| [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) | | [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) |
@ -89,20 +91,24 @@ flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the fo
additional binds: additional binds:
| Keybind | Description | | Keybind | Description |
|---------+--------------------------------------------| |---------+-----------------------------------------------|
| [[kbd:][TAB]] | Complete | | [[kbd:][TAB]] | Complete |
| [[kbd:][TAB]] | (when completing) Go to next candidate | | [[kbd:][TAB]] | (when completing) Go to next candidate |
| [[kbd:][S-TAB]] | (when completing) Go to previous candidate | | [[kbd:][S-TAB]] | (when completing) Go to previous candidate |
| [[kbd:][DEL]] | (when completing) Reset completion DWIM-style |
** Searching with multiple keywords ** Searching with multiple keywords
If the [[doom-module::completion corfu +orderless]] flag is enabled, users can If the [[doom-module::completion corfu +orderless]] flag is enabled, users can perform code
perform code completion with multiple search keywords by use of space as completion with multiple search keywords by use of space as the separator. More
separator. More information can be found [[https://github.com/oantolin/orderless#company][here]]. Pressing [[kdb:][C-SPC]] again while information can be found [[https://github.com/oantolin/orderless#company][here]]. Pressing [[kdb:][C-SPC]] again while completing inserts a
completing inserts a space as separator. This allows searching with space as separator. This allows searching with space-separated terms; each piece
space-separated terms; each piece will match individually and in any order, with will match individually and in any order, with smart casing. Pressing just [[kbd:][SPC]]
smart casing. Pressing just [[kbd:][SPC]] acts as normal and restarts completion, so that acts as normal and restarts completion, so that when typing sentences it doesn't
when typing sentences it doesn't try to complete the whole sentence instead of try to complete the whole sentence instead of just the word.
just the word.
Furthermore, if you also have [[var:+orderless-wildcard-character]] set (by default
it's the comma key), then that character acts as a wildcard when typed
mid-completion.
** Exporting to the minibuffer (requires [[doom-module::completion vertico]]) ** Exporting to the minibuffer (requires [[doom-module::completion vertico]])
When using the [[doom-module::completion vertico]] module, which pulls in the When using the [[doom-module::completion vertico]] module, which pulls in the
@ -122,28 +128,42 @@ A few variables may be set to change behavior of this module:
Configures behavior for exact matches. Its default is nil, and it's Configures behavior for exact matches. Its default is nil, and it's
recommended to leave it at that. Otherwise, single matches on snippet keys recommended to leave it at that. Otherwise, single matches on snippet keys
expand immediately. expand immediately.
- [[var:+corfu-completion-styles]] :: - [[var:+orderless-wildcard-character]] ::
Used to override [[var:completion-styles]] for corfu invocations, such that it Used for fuzzy-matching corfu invocations as an escapable alternative to
can have a value separate from, say, [[doom-package:consult]]. ~corfu-separator~. Defaults to comma.
- [[var:+corfu-icon-mapping]] :: - [[var:+cape-buffer-scanning-size-limit:]] ::
Configures icons used for each completion. See its documentation for details. Sets the maximum buffer size to be scanned by ~cape-dabbrev~ and
~cape-lines~. Defaults to 1 MB. Set this if you are having performance
problems using ~cape-dabbrev~.
** Adding CAPFs to a mode ** Adding CAPFs to a mode
To add other CAPFs on a mode-per-mode basis, put either of the following in your To add other CAPFs on a mode-per-mode basis, put either of the following in your
~config.el~: ~config.el~:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(add-hook! some-mode (add-to-list 'completion-at-point-functions #'some-capf)) (add-hook! some-mode (add-hook 'completion-at-point-functions #'some-capf depth t))
;; OR, but note the different call signature ;; OR, but note the different call signature
(add-hook 'some-mode-hook (lambda () (add-to-list 'completion-at-point-functions #'some-capf))) (add-hook 'some-mode-hook (lambda () (add-hook 'completion-at-point-functions #'some-capf depth t)))
#+end_src #+end_src
Also see ~add-hook!~'s documentation for additional ways to call it. DEPTH above is an integer between -100, 100, and defaults to 0 of ommited. Also
~add-hook~ only accepts the quoted arguments form above. see ~add-hook!~'s documentation for additional ways to call it. ~add-hook~ only
accepts the quoted arguments form above.
* Troubleshooting * Troubleshooting
[[doom-report:][Report an issue?]] [[doom-report:][Report an issue?]]
If you have performance issues with ~cape-dabbrev~, the first thing I recommend
doing is looking at the list of buffers Dabbrev is scanning with:
#+begin_src emacs-lisp
(dabbrev--select-buffers) ; => (#<buffer README.org> #<buffer config.el<3>> #<buffer cape.el> ...)
(length (dabbrev--select-buffers)) ; => 37
#+end_src
and modifying ~dabbrev-ignored-buffer-regexps~ or ~dabbrev-ignored-buffer-modes~
accordingly.
* Frequently asked questions * Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] /This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]]

View file

@ -0,0 +1,18 @@
;;; completion/corfu/autoload/commands.el -*- lexical-binding: t; -*-
;;;###autoload
(defun corfu-move-to-minibuffer ()
;; Taken from corfu's README.
;; TODO: extend this to other completion front-ends.
(interactive)
(let ((completion-extra-properties corfu--extra)
(completion-cycle-threshold completion-cycling))
(apply #'consult-completion-in-region completion-in-region--data)))
;;;###autoload
(defun +corfu-insert-wildcard-separator ()
;; I had to rename this command so that it doesn't start with "corfu-".
;; Otherwise, it does not insert the completion when +tng is enabled.
(interactive)
(setq this-command #'corfu-insert-separator)
(call-interactively #'corfu-insert-separator))

View file

@ -1,58 +1,17 @@
;;; completion/corfu/config.el -*- lexical-binding: t; -*- ;;; completion/corfu/config.el -*- lexical-binding: t; -*-
(defvar +corfu-completion-styles '(basic partial-completion flex) (defvar +cape-buffer-scanning-size-limit (* 1 1024 1024) ; 1 MB
"Completion styles for corfu to use. "Size limit for a buffer to be scanned by `cape-line' or `cape-dabbrev'.
If the user enables +orderless, `orderless' is automatically appended to this As an exception, `cape-line' will also scan buffers with the same
list before fowarding to `completion-styles'.") major mode regardless of size.")
(defvar +corfu-icon-mapping (defvar +orderless-wildcard-character ?,
`((array ,(nerd-icons-codicon "nf-cod-symbol_array") :face font-lock-type-face) "A character used as a wildcard in Corfu for fuzzy autocompletion. If you
(boolean ,(nerd-icons-codicon "nf-cod-symbol_boolean") :face font-lock-builtin-face) want to match the wildcard literally in completion, you can
(class ,(nerd-icons-codicon "nf-cod-symbol_class") :face font-lock-type-face) escape it with forward slash. Do NOT set this to SPC.
(color ,(nerd-icons-codicon "nf-cod-symbol_color") :face success)
(command ,(nerd-icons-codicon "nf-cod-terminal") :face default)
(constant ,(nerd-icons-codicon "nf-cod-symbol_constant") :face font-lock-constant-face)
(constructor ,(nerd-icons-codicon "nf-cod-triangle_right") :face font-lock-function-name-face)
(enummember ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum-member ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum ,(nerd-icons-codicon "nf-cod-symbol_enum") :face font-lock-builtin-face)
(event ,(nerd-icons-codicon "nf-cod-symbol_event") :face font-lock-warning-face)
(field ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-variable-name-face)
(file ,(nerd-icons-codicon "nf-cod-symbol_file") :face font-lock-string-face)
(folder ,(nerd-icons-codicon "nf-cod-folder") :face font-lock-doc-face)
(interface ,(nerd-icons-codicon "nf-cod-symbol_interface") :face font-lock-type-face)
(keyword ,(nerd-icons-codicon "nf-cod-symbol_keyword") :face font-lock-keyword-face)
(macro ,(nerd-icons-codicon "nf-cod-symbol_misc") :face font-lock-keyword-face)
(magic ,(nerd-icons-codicon "nf-cod-wand") :face font-lock-builtin-face)
(method ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(function ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(module ,(nerd-icons-codicon "nf-cod-file_submodule") :face font-lock-preprocessor-face)
(numeric ,(nerd-icons-codicon "nf-cod-symbol_numeric") :face font-lock-builtin-face)
(operator ,(nerd-icons-codicon "nf-cod-symbol_operator") :face font-lock-comment-delimiter-face)
(param ,(nerd-icons-codicon "nf-cod-symbol_parameter") :face default)
(property ,(nerd-icons-codicon "nf-cod-symbol_property") :face font-lock-variable-name-face)
(reference ,(nerd-icons-codicon "nf-cod-references") :face font-lock-variable-name-face)
(snippet ,(nerd-icons-codicon "nf-cod-symbol_snippet") :face font-lock-string-face)
(string ,(nerd-icons-codicon "nf-cod-symbol_string") :face font-lock-string-face)
(struct ,(nerd-icons-codicon "nf-cod-symbol_structure") :face font-lock-variable-name-face)
(text ,(nerd-icons-codicon "nf-cod-text_size") :face font-lock-doc-face)
(typeparameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(type-parameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(unit ,(nerd-icons-codicon "nf-cod-symbol_ruler") :face font-lock-constant-face)
(value ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-builtin-face)
(variable ,(nerd-icons-codicon "nf-cod-symbol_variable") :face font-lock-variable-name-face)
(t ,(nerd-icons-codicon "nf-cod-code") :face font-lock-warning-face))
"Mapping of completion kinds to icons.
It should be a list of elements with the form (KIND ICON-TXT [:face FACE]). This variable needs to be set at the top-level before any `after!' blocks.")
KIND is a symbol determining what the completion is, and comes from calling the
`:company-kind' property of the completion. ICON-TXT is a string with the icon
to use, usually as a character from the `nerd-icons' symbol font. See that
package for how to get these. Note that it can be simple text if that is
preferred. FACE, if present, is applied to the icon, mainly for its color. The
special `t' symbol should be used for KIND to represent the default icon, and
must be present.")
;; ;;
;;; Packages ;;; Packages
@ -61,7 +20,7 @@ must be present.")
:hook (org-mode . corfu-mode) :hook (org-mode . corfu-mode)
:init :init
;; Auto-completion settings, must be set before calling `global-corfu-mode'. ;; 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 (setq corfu-auto t
corfu-auto-delay 0.1 corfu-auto-delay 0.1
corfu-auto-prefix 2 corfu-auto-prefix 2
@ -70,10 +29,11 @@ must be present.")
help-mode help-mode
gud-mode gud-mode
vterm-mode)) vterm-mode))
(map! (:unless (modulep! +tng)
:i "C-SPC" #'completion-at-point))
:config :config
(setq corfu-cycle t (setq corfu-cycle t
corfu-separator (when (modulep! +orderless) ?\s) corfu-preselect (if (modulep! :completion corfu +tng) 'prompt t)
corfu-preselect t
corfu-count 16 corfu-count 16
corfu-max-width 120 corfu-max-width 120
corfu-preview-current 'insert corfu-preview-current 'insert
@ -84,52 +44,131 @@ must be present.")
;; However, it should otherwise behave like normal, whatever normal was. ;; However, it should otherwise behave like normal, whatever normal was.
tab-always-indent (if (modulep! +tng) 'complete tab-always-indent)) tab-always-indent (if (modulep! +tng) 'complete tab-always-indent))
(when (modulep! +orderless) (defun corfu-disable-in-minibuffer-p ()
(after! 'lsp-mode (or (bound-and-true-p mct--active)
(add-to-list 'completion-category-overrides (bound-and-true-p vertico--input)
`(lsp-capf (styles ,@+corfu-completion-styles ,(when (modulep! +orderless) 'orderless))))) (and (featurep 'helm-core) (helm--alive-p))
(after! 'eglot (eq (current-local-map) read-passwd-map)))
(add-to-list 'completion-category-overrides
`(eglot (styles ,@+corfu-completion-styles ,(when (modulep! +orderless) 'orderless)))))) (defun corfu-enable-in-minibuffer ()
"Enable Corfu in the minibuffer if `completion-at-point' is bound."
(unless (corfu-disable-in-minibuffer-p)
(setq-local corfu-echo-delay nil ;; Disable automatic echo and popup
corfu-popupinfo-delay nil)
(corfu-mode 1)))
(add-hook 'minibuffer-setup-hook #'corfu-enable-in-minibuffer)
(defun corfu-visible-p ()
(or (and (frame-live-p corfu--frame)
(frame-visible-p corfu--frame))
(and (featurep 'corfu-terminal)
(popon-live-p corfu-terminal--popon))))
;; 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 (corfu-visible-p)
(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)
;; Pending a PR I am making to expose `anzu--update-timer'.
(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)))))
;; Do not make us type RET twice with Corfu.
(defun corfu--maybe-return-filter (cmd)
(if (eq corfu--index -1) (corfu-quit) cmd))
(keymap-set corfu-map "RET" `(menu-item "corfu-maybe-return" corfu-insert
:filter corfu--maybe-return-filter))
(keymap-set
corfu-map "<return>" `(menu-item "corfu-maybe-return" corfu-insert
:filter corfu--maybe-return-filter))
;; Allow completion after `:' in Lispy.
(add-to-list 'corfu-auto-commands #'lispy-colon)
(when (and (modulep! +orderless)
+orderless-wildcard-character)
(defmacro +orderless-escapable-split-fn (char)
(let ((char-string (string (if (symbolp char) (symbol-value char) char))))
`(defun +orderless-escapable-split-on-space-or-char (s)
(mapcar
(lambda (piece)
(replace-regexp-in-string
(string 1) ,char-string
(replace-regexp-in-string
(concat (string 0) "\\|" (string 1))
(lambda (x)
(pcase x
("\0" " ")
("\1" ,char-string)
(_ x)))
piece
;; These are arguments to `replace-regexp-in-string'.
'fixedcase 'literal)
'fixedcase 'literal))
(split-string (replace-regexp-in-string
(concat "\\\\\\\\\\|\\\\ \\|\\\\"
,char-string)
(lambda (x)
(pcase x
("\\ " "\0")
(,(concat "\\" char-string)
"\1")
(_ x)))
s 'fixedcase 'literal)
,(concat "[ " char-string "]+")
t)))))
(after! orderless
;; Orderless splits the string into components and then determines the
;; matching style for each component. This is all regexp stuff.
(setq orderless-component-separator
(+orderless-escapable-split-fn +orderless-wildcard-character))
(setq corfu-separator +orderless-wildcard-character)
(keymap-set corfu-map (char-to-string +orderless-wildcard-character)
#'+corfu-insert-wildcard-separator)
;; Quit completion after typing the wildcard followed by a space.
(keymap-set corfu-map "SPC"
`(menu-item "corfu-maybe-quit" nil
:filter
,(lambda (_)
(when (and (> (point) (point-min))
(eq (char-before)
+orderless-wildcard-character))
(corfu-quit)
nil))))))
(add-hook! 'evil-insert-state-exit-hook
(defun +corfu-quit-on-evil-insert-state-exit-h ()
;; This predicate a workaround for unexpected calls to `corfu-quit' in
;; :company-doc-buffer buffers. This was specifically happening when using
;; `yasnippet-capf' and `company-yasnippet'.
(when (eq (current-buffer) (window-buffer (selected-window)))
(corfu-quit))))
;; For the icons, we use a custom margin formatter, which simply reads the
;; mapping in `+corfu-icon-mapping'.
(when (modulep! +icons) (when (modulep! +icons)
(defun icon-margin-formatter (metadata) (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
(when-let ((kindfunc (or (plist-get completion-extra-properties :company-kind)
(assq 'company-kind metadata))))
(lambda (cand)
(let* ((kind (funcall kindfunc cand))
(icon-entry (assq (or kind t) +corfu-icon-mapping))
(str (cadr icon-entry))
(props (cddr icon-entry))
(extra-face (plist-get props :face))
(space (propertize " " 'display '(space :width 1)))
(str (concat " " str space)))
(when extra-face
(put-text-property 0 3 'face extra-face str))
str))))
(setq corfu-margin-formatters '(icon-margin-formatter)))
;; This is to decouple the use of `completion-styles' in corfu from other ;; Reset completion DWIM-style with backspace.
;; completion packages, such as vertico. That way, the user can leave the (when (modulep! +tng)
;; global value of the variable alone, say, to be used by the default (defun corfu--maybe-reset-backspace-filter (cmd)
;; front-end or consult. The vertico module also does something similar with (when (and (> corfu--index -1)
;; `+vertico-company-completion-styles'. (eq corfu-preview-current 'insert))
(defadvice! +corfu--completion-styles (orig &rest args) cmd))
"Try default completion styles before orderless. (keymap-set corfu-map "DEL" `(menu-item "corfu-maybe-reset" corfu-reset
:filter corfu--maybe-reset-backspace-filter))
(keymap-set
corfu-map "<backspace>" `(menu-item "corfu-maybe-reset" corfu-reset
:filter corfu--maybe-reset-backspace-filter)))
Meant as :around advice for `corfu--recompute'." (map! (:map 'corfu-map
:around #'corfu--recompute
(let ((completion-styles
(append +corfu-completion-styles (when (modulep! +orderless)
'(orderless))))
completion-category-overrides completion-category-defaults)
(apply orig args)))
(map! (:unless (modulep! +tng)
"C-SPC" #'completion-at-point)
(:map 'corfu-map
(:when (modulep! +orderless) (:when (modulep! +orderless)
"C-SPC" #'corfu-insert-separator) "C-SPC" #'corfu-insert-separator)
(:when (modulep! +tng) (:when (modulep! +tng)
@ -143,28 +182,86 @@ Meant as :around advice for `corfu--recompute'."
[return] #'corfu-insert)) [return] #'corfu-insert))
(after! vertico (after! vertico
;; Taken from corfu's README. (map! :map 'corfu-map "M-m" #'corfu-move-to-minibuffer)
;; TODO: extend this to other completion front-ends. (after! evil-collection-corfu
(defun corfu-move-to-minibuffer () (evil-collection-define-key 'insert 'corfu-map
(interactive) (kbd "M-j") #'corfu-move-to-minibuffer))))
(let ((completion-extra-properties corfu--extra)
(completion-cycle-threshold completion-cycling))
(apply #'consult-completion-in-region completion-in-region--data)))
(map! :map 'corfu-map "s-<down>" #'corfu-move-to-minibuffer
(:when (modulep! :editor evil) "s-j" #'corfu-move-to-minibuffer))))
(use-package! cape (use-package! cape
:after corfu :defer t
:config :init
(add-hook! prog-mode (add-to-list 'completion-at-point-functions #'cape-file)) ;; Set up `cape-dabbrev' and `cape-line' options.
(add-hook! (org-mode markdown-mode) (add-to-list 'completion-at-point-functions #'cape-elisp-block)) (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))
;; Complete emojis :).
(when (> emacs-major-version 28)
(add-hook! (prog-mode conf-mode)
(add-hook 'completion-at-point-functions
(cape-capf-inside-faces
(cape-capf-prefix-length #'cape-emoji 1)
;; Only call inside comments and docstrings.
'tree-sitter-hl-face:doc 'font-lock-doc-face
'font-lock-comment-face 'tree-sitter-hl-face:comment)
10 t))
(add-hook! text-mode
(add-hook 'completion-at-point-functions
(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))
;; Make these capfs composable.
(advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)
(advice-add #'eglot-completion-at-point :around #'cape-wrap-nonexclusive)
(advice-add #'lsp-completion-at-point :around #'cape-wrap-nonexclusive)
(advice-add #'pcomplete-completions-at-point :around #'cape-wrap-nonexclusive)
;; From the `cape' readme. Without this, Eshell autocompletion is broken on
;; Emacs28.
(when (< emacs-major-version 29)
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify))
(advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible)) (advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible))
(use-package! yasnippet-capf (use-package! yasnippet-capf
:after corfu :when (modulep! :editor snippets)
:config :defer t
(add-hook 'yas-minor-mode-hook :init
(lambda () (add-to-list 'completion-at-point-functions #'yasnippet-capf)))) (add-hook! yas-minor-mode
(add-hook 'completion-at-point-functions #'yasnippet-capf 30 t)))
(use-package! corfu-terminal (use-package! corfu-terminal
:when (not (display-graphic-p)) :when (not (display-graphic-p))
@ -172,11 +269,13 @@ Meant as :around advice for `corfu--recompute'."
;; ;;
;;; Extensions ;;; Extensions
(use-package! corfu-history (use-package! corfu-history
:after savehist
:hook (corfu-mode . corfu-history-mode) :hook (corfu-mode . corfu-history-mode)
:config :config
(add-to-list 'savehist-additional-variables 'corfu-history)) (after! savehist (add-to-list 'savehist-additional-variables 'corfu-history)))
(use-package! corfu-popupinfo (use-package! corfu-popupinfo
:hook (corfu-mode . corfu-popupinfo-mode) :hook (corfu-mode . corfu-popupinfo-mode)
:config :config

View file

@ -1,13 +1,14 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; completion/corfu/packages.el ;;; completion/corfu/packages.el
(package! corfu :recipe (:files ("*.el" "extensions/*.el")) :pin "cc244c54b392ce4d27ed166730efde4f4d01a07f") (package! corfu :recipe (:files ("*.el" "extensions/*.el")))
(package! cape :pin "4506ee82129a8e9ff9e4650a9b16eb8c4ae355f3") (package! cape)
(when (modulep! +icons) (when (modulep! +icons)
(package! nerd-icons-completion :pin "c2db8557a3c1a9588d111f8c8e91cae96ee85010")) (package! nerd-icons-completion :pin "c2db8557a3c1a9588d111f8c8e91cae96ee85010")
(package! nerd-icons-corfu :pin "5082a22dfbdea092fcc475db3484cb3ff812b730"))
(when (modulep! +orderless) (when (modulep! +orderless)
(package! orderless :pin "e6784026717a8a6a7dcd0bf31fd3414f148c542e")) (package! orderless))
(when (modulep! :os tty) (when (modulep! :os tty)
(package! corfu-terminal :pin "501548c3d51f926c687e8cd838c5865ec45d03cc")) (package! corfu-terminal))
(when (modulep! :editor snippets) (when (modulep! :editor snippets)
(package! yasnippet-capf :pin "40654214db7a44db3a99321447632b43a10fae57")) (package! yasnippet-capf))

View file

@ -5,20 +5,18 @@
;; on the command line, then restart Emacs for the changes to take effect -- or ;; on the command line, then restart Emacs for the changes to take effect -- or
;; use 'M-x doom/reload'. ;; use 'M-x doom/reload'.
(unpin! compat) ;; (unpin! compat)
(unpin! doom-themes) (unpin! doom-themes)
(unpin! lsp-mode) ;; (unpin! lsp-mode)
(unpin! sly) (unpin! sly)
(unpin! racket-mode) (unpin! racket-mode)
(unpin! lsp-mode)
;; (unpin! better-jumper)
;; (unpin! pcre2el)
(unpin! consult) (unpin! consult)
(unpin! vertico) (unpin! vertico)
(unpin! embark) (unpin! embark)
(unpin! orderless) (unpin! orderless)
(unpin! cape)
(unpin! geiser) (unpin! corfu)
;; (unpin! geiser)
(package! nerd-icons-completion) (package! nerd-icons-completion)
(package! nerd-icons-dired) (package! nerd-icons-dired)
@ -33,8 +31,6 @@
(package! tidal) (package! tidal)
(package! fish-mode) (package! fish-mode)
(package! smart-tabs-mode) (package! smart-tabs-mode)
(package! arduino-mode)
(package! arduino-cli-mode)
(package! sclang (package! sclang
:recipe (:local-repo "/Users/emenel/Library/Application Support/SuperCollider/downloaded-quarks/scel/el")) :recipe (:local-repo "/Users/emenel/Library/Application Support/SuperCollider/downloaded-quarks/scel/el"))
(package! ijanet (package! ijanet