refactor(corfu): settings and keybinding overhaul

Previously, a distinction was made only between "regular" style (assumed
to be for people who prefer to cycle directionally and commit with RET)
and +tng (assumed to be for people who prefer TAB and auto-commit). This
made composing further variations harder on the user, as they would have
to work around our bindings. Now we have many features as documentation,
and the user can compose to their liking. The global CAPF list was
pruned, suggesting to use individual keys for those functions if
required.
This commit is contained in:
Luigi Sartor Piucco 2024-03-02 13:10:00 -03:00
parent 3aa1ea74d9
commit 9e7967c909
No known key found for this signature in database
GPG key ID: 6FF1A01853A47A66
7 changed files with 177 additions and 241 deletions

View file

@ -6,11 +6,15 @@
* Description :unfold: * Description :unfold:
This module provides code completion, powered by [[doom-package:corfu]]. This module provides code completion, powered by [[doom-package:corfu]].
It is recommended to enable either this or [[doom-module::completion company]], in It is recommended to enable either this or [[doom-module::completion company]] in
case you desire pre-configured auto-completion. Corfu is much lighter weight and case you desire pre-configured auto-completion. Corfu is much lighter weight and
focused, plus it's built on native Emacs functionality, whereas company is heavy focused, plus it's built on native Emacs functionality, whereas Company is heavy
and highly non-native, but has some extra features and more maturity. and highly non-native, but has some extra features and more maturity.
If you choose Corfu, we also highly recomend reading [[https://github.com/minad/corfu][its README]] and [[https://github.com/minad/cape][cape's
README]], as the backend is very configurable and provides many power-user
utilities for fine-tuning. Only some of common behaviors are documented here.
** Maintainers ** Maintainers
- [[doom-user:][@LuigiPiucco]] - [[doom-user:][@LuigiPiucco]]
@ -19,21 +23,12 @@ and highly non-native, but has some extra features and more maturity.
** Module flags ** Module flags
- +icons :: - +icons ::
Display icons beside completion suggestions. Display icons beside completion suggestions.
- +tng ::
Known as Tab'n'Go to Company users, changes behavior to 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 :: - +orderless ::
Pull in [[doom-package:orderless]] if necessary and apply multi-component Pull in [[doom-package:orderless]] if necessary and apply multi-component
completion (still needed if [[doom-module::completion vertico]] is active). completion (still needed if [[doom-module::completion vertico]] is active).
- +dabbrev :: - +dabbrev ::
Enable and configure [[doom-package:dabbrev]] as a close-to-universal CAPF Enable and configure [[doom-package:dabbrev]] as a close-to-universal CAPF
fallback. 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 ** Packages
- [[doom-package:corfu]] - [[doom-package:corfu]]
@ -66,67 +61,90 @@ words. Snippets may also appear in the candidate list if available.
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
#+end_quote #+end_quote
** Code completion
By default, completion gets triggered after typing 2 non-space consecutive By default, completion gets triggered after typing 2 non-space consecutive
characters, or by means of the [[kbd:][C-SPC]] keybinding at any moment. While the popup characters, by means of [[kbd:][C-SPC]] at any moment or [[kbd:][TAB]] on a line with proper
is visible, the following relevant keys are available: indentation. Many styles of completion are documented below, which can be
composed to suit the user. The following keybindings are generally available:
| Keybind | Description | | Keybind | Description |
|----------+-----------------------------------------------------------| |---------+--------------------------------------------|
| [[kbd:][<down>]] | Go to next candidate | | [[kbd:][C-n]] | Go to next candidate |
| [[kbd:][<up>]] | Go to previous candidate | | [[kbd:][C-p]] | Go to previous candidate |
| [[kbd:][C-n]] | Go to next candidate | | [[kbd:][C-S-n]] | Go to next doc line |
| [[kbd:][C-p]] | Go to previous candidate | | [[kbd:][C-S-p]] | Go to previous doc line |
| [[kbd:][C-j]] | (evil) Go to next candidate | | [[kbd:][C-S-s]] | Export to minibuffer |
| [[kbd:][C-k]] | (evil) Go to previous candidate | | [[kbd:][DEL]] | Reset completion DWIM |
| [[kbd:][C-<down>]] | Go to next doc line | | [[kbd:][TAB]] | (when not completing) Indent or complete |
| [[kbd:][C-<up>]] | Go to previous doc line | | [[kbd:][C-SPC]] | (when not completing) Complete |
| [[kbd:][C-S-n]] | Go to next doc line | | [[kbd:][C-u]] | (evil) Go to next candidate page |
| [[kbd:][C-S-p]] | Go to previous doc line | | [[kbd:][C-d]] | (evil) Go to previous candidate page |
| [[kbd:][C-S-j]] | (evil) Go to next doc line | | [[kbd:][C-h]] | (evil) Toggle documentation (if available) |
| [[kbd:][C-S-k]] | (evil) Go to previous doc line | | [[kbd:][M-t]] | (emacs) (when not completing) Complete |
| [[kbd:][C-h]] | Toggle documentation (if available) |
| [[kbd:][C-S-s]] | Export to minibuffer (if [[doom-module::completion vertico]]) |
| [[kbd:][RET]] | Insert candidate |
| [[kbd:][SPC]] | Quit autocompletion or pass-through after a wildcard |
| [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) |
| [[kbd:][C-SPC]] | (when completing) Insert separator DWIM (see below) |
If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module::completion Bindings in the following sections are additive, and get enabled by including
corfu +tng]] flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the the corresponding ~config.el~ snippets or via flags. Additionally, for users of
following additional binds: evil, [[kdb:][C-SPC]] is smart regarding your state. In normal-like states, enter insert
then start corfu; in visual-like states, perform [[help:evil-change][evil-change]] (which leaves you
in insert state) then start corfu; in insert-like states, start corfu
immediatelly.
| Keybind | Description | ** Commit preview on type
|---------+-----------------------------------------------| When the completion popup is visible, by default the current candidate is
| [[kbd:][TAB]] | Complete | previewed into the buffer, and further input commits that candidate as previewed
| [[kbd:][TAB]] | (when completing) Go to next candidate | (note it does not perform candidate exit actions, such as expanding snippets).
| [[kbd:][S-TAB]] | (when completing) Go to previous candidate | If neither ~+on-ret~ or ~+on-ret-pt~ are enabled, this becomes the only default
| [[kbd:][DEL]] | (when completing) Reset completion DWIM-style | way to commit a candidate ([[kbd:][RET]] is unbound in that case).
*** Completion in the minibuffer The feature is in line with other common editors, but if you prefer the preview
In the minibuffer, sometimes autocompletion can interfere with your goal; to be only visual or for there to be no preview, configure
Imagine you're composing a search pattern incrementally, and you find what you [[var:corfu-preview-current]].
want early, with only half the word. You then press [[kbd:RET]]. If completion
kicked in as you typed, you may lose the match, since it will complete the
first candidate. On the other hand, if you were paying attention to the
suggestions and selecting one appropriate, that's desired behavior, and you may
even desire to modify the prompt further (if you were composing a command
instead, you may want to extend it after the candidate). To allow better
control, there are 3 confirm bindings when Corfu appears in the minibuffer:
| Keybind | Description | #+begin_src emacs-lisp
|-----------+--------------------------------------------------------------------| ;; Non-inserting preview
| [[kbd:RET]] | Accept the candidate only | (setq corfu-preview-current t)
| [[kbd:C-RET]] | Confirm the current prompt only | ;; No preview
| [[kbd:S-RET]] | Accept the candidate then immediately confirm the completed prompt | (setq corfu-preview-current nil)
#+end_src
- Use [[kbd:RET]] when you want to continue composing after completing; ** Commit on [[kbd:][RET]] with pass-through
- Use [[kbd:C-RET]] when you already have the desired string, and completing would A lot of people like to use [[kbd:][RET]] to commit, so here we bind it to Corfu's
break it; insertion function. Note that Corfu allows "no candidate" to be selected, and in
- Use [[kbd:S-RET]] when you know the composition will be finished after completion that case, we have a custom binding to quit completion and pass-through. To make
(thus avoiding the need to type [[kbd:RET]] twice); it less obtrusive by default, the popup starts in this unselected state. See
[[var:corfu-preselect]] to alter the initial behavior; it can start with the first
one selected, for instance. Then, you have to move one candidate backwards to
pass-through The exact action of [[kbd:][RET]] can be changed via
[[var:+corfu-want-ret-to-confirm]].
** Searching with multiple keywords | Keybind | Description |
|---------+-----------------------|
| [[kbd:][RET]] | Insert candidate DWIM |
** Cycle directionally
If you'd rather think in directions rather than next/previous, arrow keys and vi
movements to control the selection and documentation view are bound by default.
You may unbind them by setting to nil, see ~map!~'s documentation.
| Keybind | Description |
|----------+---------------------------------|
| [[kbd:][<down>]] | Go to next candidate |
| [[kbd:][<up>]] | Go to previous candidate |
| [[kbd:][C-j]] | (evil) Go to next candidate |
| [[kbd:][C-k]] | (evil) Go to previous candidate |
| [[kbd:][C-<down>]] | Go to next doc line |
| [[kbd:][C-<up>]] | Go to previous doc line |
| [[kbd:][C-S-j]] | (evil) Go to next doc line |
| [[kbd:][C-S-k]] | (evil) Go to previous doc line |
** Cycle with [[kbd:][TAB]]
[[kbd:][TAB]]-based cycling alternatives are also bound according to the table below:
| Keybind | Description |
|---------+--------------------------|
| [[kbd:][TAB]] | Go to next candidate |
| [[kbd:][S-TAB]] | Go to previous candidate |
** Searching with multiple keywords (~+orderless~)
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 completion with multiple search keywords by use of space as the perform code completion with multiple search keywords by use of space as the
separator. More information can be found [[https://github.com/oantolin/orderless#company][here]]. Pressing [[kdb:][C-SPC]] again while separator. More information can be found [[https://github.com/oantolin/orderless#company][here]]. Pressing [[kdb:][C-SPC]] again while
@ -139,38 +157,18 @@ backslash, including the space in the search term, and pressing it with an
already escaped separator before point deletes it. Thus, you can cycle back if already escaped separator before point deletes it. Thus, you can cycle back if
you accidentaly press more than needed. you accidentaly press more than needed.
Additionally, for users of evil and regular corfu style, [[kdb:][C-SPC]] is smart | Keybind | Description |
regarding your state. In normal-like states, enter insert then start corfu; in |---------+-------------------------------------------------|
visual-like states, perform [[help:evil-change][evil-change]] (which leaves you in insert state) then | [[kbd:][C-SPC]] | (evil) (when completing) Insert separator DWIM |
start corfu; in insert-like states, start corfu immediatelly. | [[kbd:][M-SPC]] | (emacs) (when completing) Insert separator DWIM |
| [[kbd:][SPC]] | (when completing) Quit autocompletion |
| [[kbd:][SPC]] | (when completing with separators) Self-insert |
** Exporting to the minibuffer ** Exporting to the minibuffer
The entries shown in the completion popup can be exported to a ~completing-read~ The entries shown in the completion popup can be exported to another
minibuffer, giving access to all the manipulations that suite allows. Using ~completion-in-region~ minibuffer, giving access to all the manipulations those
Vertico for instance, one could use this to export with [[doom-package:embark]] via suites allow. Using Vertico for instance, one could use this to export with
[[kbd:][C-c C-l]] and get a buffer with all candidates. [[doom-package:embark]] via [[kbd:][C-c C-l]] and get a buffer with all candidates.
** Manually call generic CAPFs
Completion at point functions have the property that, when called interactively
via their symbol, they work as a call to ~completion-at-point~ where
[[var:completion-at-point-functions]] is bound to that CAPF alone. This allows to
assign generic functions to a binding and call as needed, leaving the default
value used for most completion tasks much leaner (thus, faster and easier to
look through). This module provides some such bindings for Evil users (see the
table below), and you're free map your own of course. Emacs users have to map it
themselves for now, due to the author's lack of knowledge on ergonomic
equivalents to the Evil ones. If you have suggestions, though, we'd be happy to
know!
| Keybind | Description |
|---------+---------------------------------|
| [[kbd:][C-x]] [[kbd:][C-l]] | (insert-state) ~cape-line~ |
| [[kbd:][C-x]] [[kbd:][C-k]] | (insert-state) ~cape-keyword~ |
| [[kbd:][C-x]] [[kbd:][C-f]] | (insert-state) ~cape-file~ |
| [[kbd:][C-x]] [[kbd:][s]] | (insert-state) ~cape-dict~ |
| [[kbd:][C-x]] [[kbd:][C-s]] | (insert-state) ~yasnippet-capf~ |
| [[kbd:][C-x]] [[kbd:][C-n]] | (insert-state) ~cape-dabbrev~ |
| [[kbd:][C-x]] [[kbd:][C-p]] | (insert-state) ~cape-history~ |
* Configuration * Configuration
A few variables may be set to change behavior of this module: A few variables may be set to change behavior of this module:
@ -191,15 +189,22 @@ A few variables may be set to change behavior of this module:
- [[var:corfu-auto-prefix]] :: - [[var:corfu-auto-prefix]] ::
Number of characters till auto-completion starts to happen. Defaults to 2. Number of characters till auto-completion starts to happen. Defaults to 2.
- [[var:corfu-on-exact-match]] :: - [[var:corfu-on-exact-match]] ::
Configures behavior for exact matches. Its default is nil, and it's Configures behavior for exact matches.
recommended to leave it at that. Otherwise, single matches on snippet keys - [[var:corfu-preselect]] ::
expand immediately. Configures startup selection, choosing between the first candidate or the
prompt.
- [[var:corfu-preview-current]] ::
Configures current candidate preview.
- [[var:+corfu-buffer-scanning-size-limit]] :: - [[var:+corfu-buffer-scanning-size-limit]] ::
Sets the maximum buffer size to be scanned by ~cape-dabbrev~. Defaults to 1 Sets the maximum buffer size to be scanned by ~cape-dabbrev~. Defaults to 1
MB. Set this if you are having performance problems using the CAPF. MB. Set this if you are having performance problems using the CAPF.
- [[var:+corfu-want-C-x-bindings]] :: - [[var:+corfu-want-minibuffer-completion]] ::
Enables autocompletion backends to be bound under the ~C-x~ prefix. This Enables Corfu in the minibuffer, where it may be obtrusive. May also be set
overrides some built-in Emacs keybindings. to ~aggresive~ to enable even in some places without ~completion-at-point~.
- [[var:+corfu-want-ret-to-confirm]] ::
Enables commiting with [[RET]] when the popup is visible. Default is ~t~, may be set to
~'minibuffer~ if you want to commit both the completion and the minibuffer when
active. When ~nil~, it is always passed-through.
** 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
@ -211,24 +216,25 @@ To add other CAPFs on a mode-per-mode basis, put either of the following in your
(add-hook 'some-mode-hook (lambda () (add-hook 'completion-at-point-functions #'some-capf depth t))) (add-hook 'some-mode-hook (lambda () (add-hook 'completion-at-point-functions #'some-capf depth t)))
#+end_src #+end_src
~DEPTH~ above is an integer between -100, 100, and defaults to 0 of omitted. Also ~DEPTH~ above is an integer between -100, 100, and defaults to 0 if nil. Also
see ~add-hook!~'s documentation for additional ways to call it. ~add-hook~ only see ~add-hook!~'s documentation for additional ways to call it. ~add-hook~ only
accepts the quoted arguments form above. accepts the quoted arguments form above.
** Adding CAPFs to a key ** Adding CAPFs to a key
To add other CAPFs to keys, adapt the snippet below into your ~config.el~: You may want to add other CAPFs to keys, so as to not pollute auto completion
and use only when demanded. To do so, adapt the snippet below into your
~config.el~:
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; For binding inside `corfu-mode-map'. Line 1 ensures the binding only exists (map! :map some-mode-map
;; after some-mode-hook runs. Line 2 is needed only if the binding can't leak "C-x e" #'cape-emoji)
;; into other Corfu buffers. When neither of the above make sense, the `map!'
;; call is enough.
(add-hook! some-mode ; Only needed if the binding is mode-specific
(make-local-variable 'corfu-mode-map)
(map! :map corfu-mode-map
:prefix "C-x" ; C-x is usually used as prefix, but it's not required
"e" #'cape-emoji)) ; Evil users probably want :i to avoid this in other states
#+end_src #+end_src
It's okay to add to the mode directly because ~completion-at-point~ works
regardless of Corfu (the latter is an enhanced UI for the former). Just note not
all CAPFs are interactive to be called this way, in which case you can use
[[doom-package:cape]]'s adapter to enable this.
* Troubleshooting * Troubleshooting
[[doom-report:][Report an issue?]] [[doom-report:][Report an issue?]]

View file

@ -1,13 +1,5 @@
;;; completion/corfu/autoload.el -*- lexical-binding: t; -*- ;;; completion/corfu/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +corfu-complete-and-exit-minibuffer ()
(interactive)
(if (>= corfu--index 0)
(corfu-complete)
(corfu-insert))
(exit-minibuffer))
;;;###autoload ;;;###autoload
(defun +corfu-move-to-minibuffer () (defun +corfu-move-to-minibuffer ()
"Move the current list of candidates to your choice of minibuffer completion UI." "Move the current list of candidates to your choice of minibuffer completion UI."
@ -46,21 +38,4 @@
(save-excursion (backward-char 1) (save-excursion (backward-char 1)
(insert-char ?\\))) (insert-char ?\\)))
(t (t
;; Without this corfu quits immediately.
(setq this-command #'corfu-insert-separator)
(call-interactively #'corfu-insert-separator)))) (call-interactively #'corfu-insert-separator))))
;;;###autoload
(defun +corfu-in-doc-or-comment-p (_sym)
"Return non-nil if point is in a docstring or comment."
(or (nth 4 (syntax-ppss))
(when-let ((faces '(font-lock-comment-face
font-lock-doc-face
tree-sitter-hl-face:doc
tree-sitter-hl-face:comment))
(fs (get-text-property (point) 'face)))
(if (listp fs)
(cl-loop for f in fs
if (memq f faces)
return t)
(memq fs faces)))))

View file

@ -3,14 +3,19 @@
(defvar +corfu-buffer-scanning-size-limit (* 1 1024 1024) ; 1 MB (defvar +corfu-buffer-scanning-size-limit (* 1 1024 1024) ; 1 MB
"Size limit for a buffer to be scanned by `cape-dabbrev'.") "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.")
(defvar +corfu-want-minibuffer-completion t (defvar +corfu-want-minibuffer-completion t
"Whether to enable Corfu in the minibuffer. "Whether to enable Corfu in the minibuffer.
Setting this to `aggressive' will enable Corfu in more commands which Setting this to `aggressive' will enable Corfu in more commands which
use the minibuffer such as `query-replace'.") use the minibuffer such as `query-replace'.")
(defvar +corfu-want-ret-to-confirm t
"Configure how the user expects RET to behave.
Possible values are:
- t (default): Insert candidate if one is selected, pass-through otherwise;
- `minibuffer': Insert candidate if one is selected, pass-through otherwise,
and immediatelly exit if in the minibuffer;
- nil: Pass-through without inserting.")
;; ;;
;;; Packages ;;; Packages
(use-package! corfu (use-package! corfu
@ -50,22 +55,18 @@ use the minibuffer such as `query-replace'.")
t) t)
corfu-cycle t corfu-cycle t
corfu-separator (when (modulep! +orderless) ?\s) corfu-separator (when (modulep! +orderless) ?\s)
corfu-preselect (if (modulep! +tng) 'prompt 'valid) corfu-preselect 'prompt
corfu-count 16 corfu-count 16
corfu-max-width 120 corfu-max-width 120
corfu-preview-current 'insert corfu-preview-current 'insert
corfu-on-exact-match nil corfu-on-exact-match nil
corfu-quit-at-boundary (if (modulep! +orderless) 'separator t) corfu-quit-at-boundary (if (modulep! +orderless) 'separator t)
corfu-quit-no-match (if (modulep! +orderless) 'separator t) corfu-quit-no-match (if (modulep! +orderless) 'separator t)
;; In the case of +tng, TAB should be smart regarding completion; tab-always-indent 'complete)
;; However, it should otherwise behave like normal, whatever normal was.
tab-always-indent (if (modulep! +tng) 'complete tab-always-indent))
(add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles))) (add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles)))
(add-to-list 'corfu-auto-commands #'lispy-colon) (add-to-list 'corfu-auto-commands #'lispy-colon)
(add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer) (add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer)
(add-to-list 'corfu-continue-commands #'+corfu-smart-sep-toggle-escape)
(add-hook 'evil-insert-state-exit-hook #'corfu-quit) (add-hook 'evil-insert-state-exit-hook #'corfu-quit)
(when (modulep! +icons) (when (modulep! +icons)
@ -116,28 +117,6 @@ use the minibuffer such as `query-replace'.")
"\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?") "\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?")
dabbrev-upcase-means-case-search t) dabbrev-upcase-means-case-search t)
(add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode))) (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)
(defun +corfu-add-cape-emoji-h ()
(add-hook 'completion-at-point-functions
(cape-capf-predicate (cape-capf-prefix-length #'cape-emoji 1)
#'+corfu-in-doc-or-comment-p)
10 t)))
(add-hook! text-mode
(defun +corfu-add-cape-emoji-text-h ()
(add-hook 'completion-at-point-functions
(cape-capf-prefix-length #'cape-emoji 1) 10 t))))
;; Enable dictionary-based autocompletion.
(when (modulep! +dict)
(add-hook! (prog-mode conf-mode)
(defun +corfu-add-cape-dict-h ()
(add-hook 'completion-at-point-functions
(cape-capf-predicate #'+corfu-in-doc-or-comment-p #'cape-dict)
40 t)))
(add-hook! text-mode
(defun +corfu-add-cape-dict-text-h ()
(add-hook 'completion-at-point-functions #'cape-dict 40 t))))
;; Make these capfs composable. ;; Make these capfs composable.
(advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive) (advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)
@ -171,7 +150,6 @@ use the minibuffer such as `query-replace'.")
:config :config
(after! savehist (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

@ -537,13 +537,6 @@
"C-p" #'company-search-repeat-backward "C-p" #'company-search-repeat-backward
"C-s" (cmd! (company-search-abort) (company-filter-candidates)))) "C-s" (cmd! (company-search-abort) (company-filter-candidates))))
(:when (modulep! :completion corfu)
:after corfu
(:map corfu-mode-map
"C-M-i" #'completion-at-point)
(:map corfu-popupinfo-map
"C-S-h" #'corfu-popupinfo-toggle))
;;; ein notebooks ;;; ein notebooks
(:after ein:notebook-multilang (:after ein:notebook-multilang
:map ein:notebook-multilang-mode-map :map ein:notebook-multilang-mode-map

View file

@ -162,34 +162,32 @@
(:when (modulep! :completion corfu) (:when (modulep! :completion corfu)
(:after corfu (:after corfu
(:map corfu-mode-map (:map corfu-mode-map
:e "C-M-i" #'completion-at-point :i "C-SPC" #'completion-at-point
(:when +corfu-want-C-x-bindings :n "C-SPC" (cmd! (call-interactively #'evil-insert-state)
(:prefix "C-x" (call-interactively #'completion-at-point))
:i "C-l" #'cape-line :v "C-SPC" (cmd! (call-interactively #'evil-change)
:i "C-k" #'cape-keyword (call-interactively #'completion-at-point)))
: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)
(call-interactively #'completion-at-point))
:v "C-SPC" (cmd! (call-interactively #'evil-change)
(call-interactively #'completion-at-point))))
(:map corfu-map (:map corfu-map
"C-u" (cmd! (let (corfu-cycle) :i "C-SPC" #'corfu-insert-separator
(funcall-interactively #'corfu-next (- corfu-count)))) "C-k" #'corfu-previous
"C-d" (cmd! (let (corfu-cycle) "C-j" #'corfu-next
(funcall-interactively #'corfu-next corfu-count))))) "C-u" (cmd! (let (corfu-cycle)
(funcall-interactively #'corfu-next (- corfu-count))))
"C-d" (cmd! (let (corfu-cycle)
(funcall-interactively #'corfu-next corfu-count)))))
(:after corfu-popupinfo (:after corfu-popupinfo
:map corfu-popupinfo-map :map corfu-popupinfo-map
"C-h" #'corfu-popupinfo-toggle
;; Reversed because popupinfo assumes opposite of what feels intuitive ;; Reversed because popupinfo assumes opposite of what feels intuitive
;; with evil. ;; with evil.
"C-S-k" #'corfu-popupinfo-scroll-down "C-S-k" #'corfu-popupinfo-scroll-down
"C-S-j" #'corfu-popupinfo-scroll-up "C-S-j" #'corfu-popupinfo-scroll-up
"C-h" #'corfu-popupinfo-toggle))) "C-<up>" #'corfu-popupinfo-scroll-down
"C-<down>" #'corfu-popupinfo-scroll-up
"C-S-p" #'corfu-popupinfo-scroll-down
"C-S-n" #'corfu-popupinfo-scroll-up
"C-S-u" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-down corfu-popupinfo-min-height))
"C-S-d" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-up corfu-popupinfo-min-height)))))
;;; :completion (separate) ;;; :completion (separate)
(map! (:when (modulep! :completion ivy) (map! (:when (modulep! :completion ivy)

View file

@ -459,57 +459,42 @@ Continues comments if executed from a commented line. Consults
"C-s" command)) "C-s" command))
(map! :when (modulep! :completion corfu) (map! :when (modulep! :completion corfu)
:after corfu
(:map corfu-map (:map corfu-map
"C-S-s" #'+corfu-move-to-minibuffer "C-S-s" #'+corfu-move-to-minibuffer
"C-p" #'corfu-previous "C-p" #'corfu-previous
"C-n" #'corfu-next "C-n" #'corfu-next
"S-TAB" #'corfu-previous
[backtab] #'corfu-previous
"TAB" #'corfu-next
[tab] #'corfu-next
(:when (modulep! :completion corfu +orderless) (:when (modulep! :completion corfu +orderless)
[remap completion-at-point] #'+corfu-smart-sep-toggle-escape) [remap corfu-insert-separator] #'+corfu-smart-sep-toggle-escape)))
(:when (modulep! :completion corfu +tng) (let ((cmds-del
:gi [tab] #'corfu-next `(menu-item "Reset completion" corfu-reset
:gi "TAB" #'corfu-next :filter ,(lambda (cmd)
:gi [backtab] #'corfu-previous (interactive)
:gi "S-TAB" #'corfu-previous)) (when (and (>= corfu--index 0)
(:after corfu-popupinfo (eq corfu-preview-current 'insert))
:map corfu-popupinfo-map cmd))))
"C-<up>" #'corfu-popupinfo-scroll-down (cmds-ret
"C-<down>" #'corfu-popupinfo-scroll-up `(menu-item "Insert completion DWIM" corfu-insert
"C-S-p" #'corfu-popupinfo-scroll-down :filter ,(lambda (cmd)
"C-S-n" #'corfu-popupinfo-scroll-up (interactive)
"C-S-u" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-down corfu-popupinfo-min-height)) (cond ((null +corfu-want-ret-to-confirm)
"C-S-d" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-up corfu-popupinfo-min-height))) (corfu-quit))
(:when (not (modulep! :completion corfu +tng)) ((or (not (minibufferp nil t))
(:map corfu-map (eq +corfu-want-ret-to-confirm t))
"C-<return>" `(menu-item "Conclude the minibuffer" exit-minibuffer (when (>= corfu--index 0) cmd))
:filter ,(lambda (cmd) (when (minibufferp nil t) cmd))) ((eq +corfu-want-ret-to-confirm 'minibuffer)
"S-<return>" `(menu-item "Insert completion and conclude" (funcall-interactively cmd)
+corfu-complete-and-exit-minibuffer nil)
:filter ,(lambda (cmd) (when (minibufferp nil t) cmd)))))) (t cmd))))))
(when-let ((cmds-del (and (modulep! :completion corfu +tng)
`(menu-item "Reset completion" corfu-reset
:filter ,(lambda (cmd)
(when (and (>= corfu--index 0)
(eq corfu-preview-current 'insert))
cmd)))))
(cmds-ret `(menu-item "Insert completion" corfu-insert
:filter ,(lambda (cmd)
(cond ((eq corfu--index -1)
(corfu-quit))
((and (modulep! :completion corfu +tng)
(eq corfu-preview-current 'insert)
(minibufferp nil t))
(corfu-insert)
nil)
(t
cmd))))))
(map! :when (modulep! :completion corfu) (map! :when (modulep! :completion corfu)
:after corfu
:map corfu-map :map corfu-map
[backspace] cmds-del [backspace] cmds-del
"DEL" cmds-del "DEL" cmds-del
:ig [return] cmds-ret :gi [return] cmds-ret
:ig "RET" cmds-ret)) :gi "RET" cmds-ret))
;; Smarter C-a/C-e for both Emacs and Evil. C-a will jump to indentation. ;; Smarter C-a/C-e for both Emacs and Evil. C-a will jump to indentation.
;; Pressing it again will send you to the true bol. Same goes for C-e, except ;; Pressing it again will send you to the true bol. Same goes for C-e, except

View file

@ -22,6 +22,7 @@
:completion :completion
company ; the ultimate code completion backend company ; the ultimate code completion backend
;;(corfu +orderless) ; complete with cap(f), cape and a flying feather!
;;helm ; the *other* search engine for love and life ;;helm ; the *other* search engine for love and life
;;ido ; the other *other* search engine... ;;ido ; the other *other* search engine...
;;ivy ; a search engine for love and life ;;ivy ; a search engine for love and life