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:
parent
3aa1ea74d9
commit
9e7967c909
7 changed files with 177 additions and 241 deletions
|
@ -6,11 +6,15 @@
|
|||
* Description :unfold:
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
- [[doom-user:][@LuigiPiucco]]
|
||||
|
||||
|
@ -19,21 +23,12 @@ and highly non-native, but has some extra features and more maturity.
|
|||
** Module flags
|
||||
- +icons ::
|
||||
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 ::
|
||||
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 close-to-universal 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]]
|
||||
|
@ -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?]]
|
||||
#+end_quote
|
||||
|
||||
** Code completion
|
||||
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
|
||||
is visible, the following relevant keys are available:
|
||||
characters, by means of [[kbd:][C-SPC]] at any moment or [[kbd:][TAB]] on a line with proper
|
||||
indentation. Many styles of completion are documented below, which can be
|
||||
composed to suit the user. The following keybindings are generally available:
|
||||
|
||||
| Keybind | Description |
|
||||
|----------+-----------------------------------------------------------|
|
||||
| [[kbd:][<down>]] | Go to next candidate |
|
||||
| [[kbd:][<up>]] | Go to previous candidate |
|
||||
| [[kbd:][C-n]] | Go to next candidate |
|
||||
| [[kbd:][C-p]] | 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-n]] | Go to next doc line |
|
||||
| [[kbd:][C-S-p]] | 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 |
|
||||
| [[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) |
|
||||
| Keybind | Description |
|
||||
|---------+--------------------------------------------|
|
||||
| [[kbd:][C-n]] | Go to next candidate |
|
||||
| [[kbd:][C-p]] | Go to previous candidate |
|
||||
| [[kbd:][C-S-n]] | Go to next doc line |
|
||||
| [[kbd:][C-S-p]] | Go to previous doc line |
|
||||
| [[kbd:][C-S-s]] | Export to minibuffer |
|
||||
| [[kbd:][DEL]] | Reset completion DWIM |
|
||||
| [[kbd:][TAB]] | (when not completing) Indent or complete |
|
||||
| [[kbd:][C-SPC]] | (when not completing) Complete |
|
||||
| [[kbd:][C-u]] | (evil) Go to next candidate page |
|
||||
| [[kbd:][C-d]] | (evil) Go to previous candidate page |
|
||||
| [[kbd:][C-h]] | (evil) Toggle documentation (if available) |
|
||||
| [[kbd:][M-t]] | (emacs) (when not completing) Complete |
|
||||
|
||||
If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module::completion
|
||||
corfu +tng]] flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the
|
||||
following additional binds:
|
||||
Bindings in the following sections are additive, and get enabled by including
|
||||
the corresponding ~config.el~ snippets or via flags. Additionally, for users of
|
||||
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 |
|
||||
|---------+-----------------------------------------------|
|
||||
| [[kbd:][TAB]] | Complete |
|
||||
| [[kbd:][TAB]] | (when completing) Go to next candidate |
|
||||
| [[kbd:][S-TAB]] | (when completing) Go to previous candidate |
|
||||
| [[kbd:][DEL]] | (when completing) Reset completion DWIM-style |
|
||||
** Commit preview on type
|
||||
When the completion popup is visible, by default the current candidate is
|
||||
previewed into the buffer, and further input commits that candidate as previewed
|
||||
(note it does not perform candidate exit actions, such as expanding snippets).
|
||||
If neither ~+on-ret~ or ~+on-ret-pt~ are enabled, this becomes the only default
|
||||
way to commit a candidate ([[kbd:][RET]] is unbound in that case).
|
||||
|
||||
*** Completion in the minibuffer
|
||||
In the minibuffer, sometimes autocompletion can interfere with your goal;
|
||||
Imagine you're composing a search pattern incrementally, and you find what you
|
||||
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:
|
||||
The feature is in line with other common editors, but if you prefer the preview
|
||||
to be only visual or for there to be no preview, configure
|
||||
[[var:corfu-preview-current]].
|
||||
|
||||
| Keybind | Description |
|
||||
|-----------+--------------------------------------------------------------------|
|
||||
| [[kbd:RET]] | Accept the candidate only |
|
||||
| [[kbd:C-RET]] | Confirm the current prompt only |
|
||||
| [[kbd:S-RET]] | Accept the candidate then immediately confirm the completed prompt |
|
||||
#+begin_src emacs-lisp
|
||||
;; Non-inserting preview
|
||||
(setq corfu-preview-current t)
|
||||
;; No preview
|
||||
(setq corfu-preview-current nil)
|
||||
#+end_src
|
||||
|
||||
- Use [[kbd:RET]] when you want to continue composing after completing;
|
||||
- Use [[kbd:C-RET]] when you already have the desired string, and completing would
|
||||
break it;
|
||||
- Use [[kbd:S-RET]] when you know the composition will be finished after completion
|
||||
(thus avoiding the need to type [[kbd:RET]] twice);
|
||||
** Commit on [[kbd:][RET]] with pass-through
|
||||
A lot of people like to use [[kbd:][RET]] to commit, so here we bind it to Corfu's
|
||||
insertion function. Note that Corfu allows "no candidate" to be selected, and in
|
||||
that case, we have a custom binding to quit completion and pass-through. To make
|
||||
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
|
||||
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
|
||||
|
@ -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
|
||||
you accidentaly press more than needed.
|
||||
|
||||
Additionally, for users of evil and regular corfu style, [[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 |
|
||||
|---------+-------------------------------------------------|
|
||||
| [[kbd:][C-SPC]] | (evil) (when completing) Insert separator DWIM |
|
||||
| [[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
|
||||
The entries shown in the completion popup can be exported to a ~completing-read~
|
||||
minibuffer, giving access to all the manipulations that suite allows. Using
|
||||
Vertico for instance, one could use this to export with [[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~ |
|
||||
The entries shown in the completion popup can be exported to another
|
||||
~completion-in-region~ minibuffer, giving access to all the manipulations those
|
||||
suites allow. Using Vertico for instance, one could use this to export with
|
||||
[[doom-package:embark]] via [[kbd:][C-c C-l]] and get a buffer with all candidates.
|
||||
|
||||
* Configuration
|
||||
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]] ::
|
||||
Number of characters till auto-completion starts to happen. Defaults to 2.
|
||||
- [[var:corfu-on-exact-match]] ::
|
||||
Configures behavior for exact matches. Its default is nil, and it's
|
||||
recommended to leave it at that. Otherwise, single matches on snippet keys
|
||||
expand immediately.
|
||||
Configures behavior for exact matches.
|
||||
- [[var:corfu-preselect]] ::
|
||||
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]] ::
|
||||
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.
|
||||
- [[var:+corfu-want-C-x-bindings]] ::
|
||||
Enables autocompletion backends to be bound under the ~C-x~ prefix. This
|
||||
overrides some built-in Emacs keybindings.
|
||||
- [[var:+corfu-want-minibuffer-completion]] ::
|
||||
Enables Corfu in the minibuffer, where it may be obtrusive. May also be set
|
||||
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
|
||||
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)))
|
||||
#+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
|
||||
accepts the quoted arguments form above.
|
||||
|
||||
** 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
|
||||
;; For binding inside `corfu-mode-map'. Line 1 ensures the binding only exists
|
||||
;; after some-mode-hook runs. Line 2 is needed only if the binding can't leak
|
||||
;; 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
|
||||
(map! :map some-mode-map
|
||||
"C-x e" #'cape-emoji)
|
||||
#+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
|
||||
[[doom-report:][Report an issue?]]
|
||||
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
;;; 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
|
||||
(defun +corfu-move-to-minibuffer ()
|
||||
"Move the current list of candidates to your choice of minibuffer completion UI."
|
||||
|
@ -46,21 +38,4 @@
|
|||
(save-excursion (backward-char 1)
|
||||
(insert-char ?\\)))
|
||||
(t
|
||||
;; Without this corfu quits immediately.
|
||||
(setq this-command #'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)))))
|
||||
|
|
|
@ -3,14 +3,19 @@
|
|||
(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.")
|
||||
|
||||
(defvar +corfu-want-minibuffer-completion t
|
||||
"Whether to enable Corfu in the minibuffer.
|
||||
Setting this to `aggressive' will enable Corfu in more commands which
|
||||
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
|
||||
(use-package! corfu
|
||||
|
@ -50,22 +55,18 @@ use the minibuffer such as `query-replace'.")
|
|||
t)
|
||||
corfu-cycle t
|
||||
corfu-separator (when (modulep! +orderless) ?\s)
|
||||
corfu-preselect (if (modulep! +tng) 'prompt 'valid)
|
||||
corfu-preselect 'prompt
|
||||
corfu-count 16
|
||||
corfu-max-width 120
|
||||
corfu-preview-current 'insert
|
||||
corfu-on-exact-match nil
|
||||
corfu-quit-at-boundary (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;
|
||||
;; However, it should otherwise behave like normal, whatever normal was.
|
||||
tab-always-indent (if (modulep! +tng) 'complete tab-always-indent))
|
||||
tab-always-indent 'complete)
|
||||
(add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles)))
|
||||
(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-smart-sep-toggle-escape)
|
||||
(add-hook 'evil-insert-state-exit-hook #'corfu-quit)
|
||||
|
||||
(when (modulep! +icons)
|
||||
|
@ -116,28 +117,6 @@ use the minibuffer such as `query-replace'.")
|
|||
"\\(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)))
|
||||
;; 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.
|
||||
(advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)
|
||||
|
@ -171,7 +150,6 @@ use the minibuffer such as `query-replace'.")
|
|||
:config
|
||||
(after! savehist (add-to-list 'savehist-additional-variables 'corfu-history)))
|
||||
|
||||
|
||||
(use-package! corfu-popupinfo
|
||||
:hook ((corfu-mode . corfu-popupinfo-mode))
|
||||
:config
|
||||
|
|
|
@ -537,13 +537,6 @@
|
|||
"C-p" #'company-search-repeat-backward
|
||||
"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
|
||||
(:after ein:notebook-multilang
|
||||
:map ein:notebook-multilang-mode-map
|
||||
|
|
|
@ -162,34 +162,32 @@
|
|||
(:when (modulep! :completion corfu)
|
||||
(:after corfu
|
||||
(:map corfu-mode-map
|
||||
:e "C-M-i" #'completion-at-point
|
||||
(: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)
|
||||
(call-interactively #'completion-at-point))
|
||||
:v "C-SPC" (cmd! (call-interactively #'evil-change)
|
||||
(call-interactively #'completion-at-point))))
|
||||
: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
|
||||
"C-u" (cmd! (let (corfu-cycle)
|
||||
(funcall-interactively #'corfu-next (- corfu-count))))
|
||||
"C-d" (cmd! (let (corfu-cycle)
|
||||
(funcall-interactively #'corfu-next corfu-count)))))
|
||||
:i "C-SPC" #'corfu-insert-separator
|
||||
"C-k" #'corfu-previous
|
||||
"C-j" #'corfu-next
|
||||
"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
|
||||
:map corfu-popupinfo-map
|
||||
"C-h" #'corfu-popupinfo-toggle
|
||||
;; Reversed because popupinfo assumes opposite of what feels intuitive
|
||||
;; with evil.
|
||||
"C-S-k" #'corfu-popupinfo-scroll-down
|
||||
"C-S-j" #'corfu-popupinfo-scroll-up
|
||||
"C-h" #'corfu-popupinfo-toggle)))
|
||||
"C-S-k" #'corfu-popupinfo-scroll-down
|
||||
"C-S-j" #'corfu-popupinfo-scroll-up
|
||||
"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)
|
||||
(map! (:when (modulep! :completion ivy)
|
||||
|
|
|
@ -459,57 +459,42 @@ Continues comments if executed from a commented line. Consults
|
|||
"C-s" command))
|
||||
|
||||
(map! :when (modulep! :completion corfu)
|
||||
:after corfu
|
||||
(:map corfu-map
|
||||
"C-S-s" #'+corfu-move-to-minibuffer
|
||||
"C-p" #'corfu-previous
|
||||
"C-n" #'corfu-next
|
||||
"S-TAB" #'corfu-previous
|
||||
[backtab] #'corfu-previous
|
||||
"TAB" #'corfu-next
|
||||
[tab] #'corfu-next
|
||||
(:when (modulep! :completion corfu +orderless)
|
||||
[remap completion-at-point] #'+corfu-smart-sep-toggle-escape)
|
||||
(:when (modulep! :completion corfu +tng)
|
||||
: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-<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)))
|
||||
(:when (not (modulep! :completion corfu +tng))
|
||||
(:map corfu-map
|
||||
"C-<return>" `(menu-item "Conclude the minibuffer" exit-minibuffer
|
||||
:filter ,(lambda (cmd) (when (minibufferp nil t) cmd)))
|
||||
"S-<return>" `(menu-item "Insert completion and conclude"
|
||||
+corfu-complete-and-exit-minibuffer
|
||||
:filter ,(lambda (cmd) (when (minibufferp nil 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))))))
|
||||
[remap corfu-insert-separator] #'+corfu-smart-sep-toggle-escape)))
|
||||
(let ((cmds-del
|
||||
`(menu-item "Reset completion" corfu-reset
|
||||
:filter ,(lambda (cmd)
|
||||
(interactive)
|
||||
(when (and (>= corfu--index 0)
|
||||
(eq corfu-preview-current 'insert))
|
||||
cmd))))
|
||||
(cmds-ret
|
||||
`(menu-item "Insert completion DWIM" corfu-insert
|
||||
:filter ,(lambda (cmd)
|
||||
(interactive)
|
||||
(cond ((null +corfu-want-ret-to-confirm)
|
||||
(corfu-quit))
|
||||
((or (not (minibufferp nil t))
|
||||
(eq +corfu-want-ret-to-confirm t))
|
||||
(when (>= corfu--index 0) cmd))
|
||||
((eq +corfu-want-ret-to-confirm 'minibuffer)
|
||||
(funcall-interactively cmd)
|
||||
nil)
|
||||
(t cmd))))))
|
||||
(map! :when (modulep! :completion corfu)
|
||||
:after corfu
|
||||
:map corfu-map
|
||||
[backspace] cmds-del
|
||||
"DEL" cmds-del
|
||||
:ig [return] cmds-ret
|
||||
:ig "RET" cmds-ret))
|
||||
:gi [return] cmds-ret
|
||||
:gi "RET" cmds-ret))
|
||||
|
||||
;; 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
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
:completion
|
||||
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
|
||||
;;ido ; the other *other* search engine...
|
||||
;;ivy ; a search engine for love and life
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue