dev: merging latest changes from pr7002

This commit is contained in:
Matt Nish-Lapidus 2023-12-10 10:17:09 -05:00
commit beb37c7c16
5 changed files with 151 additions and 220 deletions

View file

@ -6,10 +6,10 @@
* 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 case you It is recommended to enable either this or [[doom-module::completion company]], in
desire pre-configured auto-completion. Corfu is much lighter weight and focused, case you desire pre-configured auto-completion. Corfu is much lighter weight and
plus it's built on native Emacs functionality, whereas company is heavy and focused, plus it's built on native Emacs functionality, whereas company is heavy
highly non-native, but has some extra features and more maturity. and highly non-native, but has some extra features and more maturity.
** Maintainers ** Maintainers
- [[doom-user:][@LuigiPiucco]] - [[doom-user:][@LuigiPiucco]]
@ -20,14 +20,14 @@ highly non-native, but has some extra features and more maturity.
- +icons :: - +icons ::
Display icons beside completion suggestions. Display icons beside completion suggestions.
- +tng :: - +tng ::
Invoke completion on [[kbd:][TAB]]. When corfu is active, [[kbd:][TAB]] and Known as Tab'n'Go to Company users, changes behavior to invoke completion on
[[kbd:][S-TAB]] will navigate the completion candidates. Arrow keys and [[kbd:][TAB]]. When Corfu is active, [[kbd:][TAB]] and [[kbd:][S-TAB]] will navigate the completion
evil-style movement are still supported. 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 nigh on everywhere CAPF Enable and configure [[doom-package:dabbrev]] as a close-to-universal CAPF
fallback. fallback.
- +dict :: - +dict ::
Enable and configure dictionary completion for text modes and related regions Enable and configure dictionary completion for text modes and related regions
@ -38,7 +38,6 @@ highly non-native, but has some extra features and more maturity.
** Packages ** Packages
- [[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-corfu]] 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]]
@ -57,7 +56,7 @@ Enable this module in your ~doom!~ block.
This module has no direct requirements, but some languages may have their own This module has no direct requirements, but some languages may have their own
requirements to fulfill before you get code completion in them (and some requirements to fulfill before you get code completion in them (and some
languages may lack code completion support altogether). Run ~$ doom doctor~ to languages may lack code completion support altogether). Run ~$ doom doctor~ to
find out if you're missing any dependencies. Note that corfu may have support find out if you're missing any dependencies. Note that Corfu may have support
for completions in languages that have no development intelligence, since it for completions in languages that have no development intelligence, since it
supports generic, context insensitive candidates such as file names or recurring supports generic, context insensitive candidates such as file names or recurring
words. Snippets may also appear in the candidate list if available. words. Snippets may also appear in the candidate list if available.
@ -88,42 +87,46 @@ is visible, the following relevant keys are available:
| [[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:][M-m]] | Export to minibuffer (if [[doom-module::completion vertico]]) | | [[kbd:][M-m]] | Export to minibuffer (if [[doom-module::completion vertico]]) |
| [[kbd:][M-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]] | (after wildcard) Reset completion | | [[kbd:][SPC]] | Quit autocompletion after a wildcard or pass-through |
| [[kbd:][DEL]] | Reset completion |
| [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) | | [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) |
| [[kbd:][C-SPC]] | (when completing) Insert separator (see below) | | [[kbd:][C-SPC]] | (when completing) Insert separator DWIM (see below) |
If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module::completion corfu +tng]] If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module::completion
flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the following corfu +tng]] flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the
additional binds: following 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 completion with multiple search keywords by use of space or ~,~ as perform code completion with multiple search keywords by use of space as the
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
completing inserts a space as separator. This allows searching with completing inserts a space as separator. This allows searching with
space-separated terms; each piece will match individually and in any order, with space-separated terms; each piece will match individually and in any order, with
smart casing. Pressing just [[kbd:][SPC]] acts as normal and quits completion, so that smart casing. Pressing just [[kbd:][SPC]] acts as normal and quits completion, so that
when typing sentences it doesn't try to complete the whole sentence instead of when typing sentences it doesn't try to complete the whole sentence instead of
just the word. just the word. Pressing [[kdb:][C-SPC]] with point after a separator escapes it with a
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.
Furthermore, if you also have [[var:+orderless-wildcard-character]] set (by default Additionally, for users of evil and regular corfu style, [[kdb:][C-SPC]] is smart
it's the comma key), then that character acts as a wildcard when typed regarding your state. In normal-like states, enter insert then start corfu; in
mid-completion. 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.
** 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
[[doom-package:consult]] package, the entries shown in the completion popup can be [[doom-package:consult]] package, the entries shown in the completion popup can be
exported to a consult minibuffer, giving access to all the manipulations the exported to a consult minibuffer, giving access to all the manipulations the
vertico suite allows. For instance, one could use this to export with Vertico suite allows. 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. [[doom-package:embark]] via [[kbd:][C-c C-l]] and get a buffer with all candidates.
* Configuration * Configuration
@ -137,13 +140,10 @@ 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:+orderless-wildcard-character]] :: - [[var:+corfu-buffer-scanning-size-limit]] ::
Used for fuzzy-matching corfu invocations as an escapable alternative to
~corfu-separator~. Defaults to comma.
- [[var:+cape-buffer-scanning-size-limit:]] ::
Sets the maximum buffer size to be scanned by ~cape-dabbrev~ and 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 ~cape-lines~. Defaults to 1 MB. Set this if you are having performance
problems using ~cape-dabbrev~. problems using either CAPF.
** 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
@ -155,7 +155,7 @@ 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 ommited. Also ~DEPTH~ above is an integer between -100, 100, and defaults to 0 of omitted. 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.
@ -163,14 +163,14 @@ accepts the quoted arguments form above.
[[doom-report:][Report an issue?]] [[doom-report:][Report an issue?]]
If you have performance issues with ~cape-dabbrev~, the first thing I recommend 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: doing is to look at the list of buffers Dabbrev is scanning:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(dabbrev--select-buffers) ; => (#<buffer README.org> #<buffer config.el<3>> #<buffer cape.el> ...) (dabbrev--select-buffers) ; => (#<buffer README.org> #<buffer config.el<3>> #<buffer cape.el> ...)
(length (dabbrev--select-buffers)) ; => 37 (length (dabbrev--select-buffers)) ; => 37
#+end_src #+end_src
and modifying ~dabbrev-ignored-buffer-regexps~ or ~dabbrev-ignored-buffer-modes~ ... and modify ~dabbrev-ignored-buffer-regexps~ or ~dabbrev-ignored-buffer-modes~
accordingly. accordingly.
* Frequently asked questions * Frequently asked questions

View file

@ -1,7 +1,7 @@
;;; completion/corfu/autoload/commands.el -*- lexical-binding: t; -*- ;;; completion/corfu/autoload.el -*- lexical-binding: t; -*-
;;;###autoload ;;;###autoload
(defun corfu-move-to-minibuffer () (defun +corfu-move-to-minibuffer ()
;; Taken from corfu's README. ;; Taken from corfu's README.
;; TODO: extend this to other completion front-ends. ;; TODO: extend this to other completion front-ends.
(interactive) (interactive)
@ -10,9 +10,16 @@
(apply #'consult-completion-in-region completion-in-region--data))) (apply #'consult-completion-in-region completion-in-region--data)))
;;;###autoload ;;;###autoload
(defun +corfu-insert-wildcard-separator () (defun +corfu-smart-sep-toggle-escape ()
;; I had to rename this command so that it doesn't start with "corfu-". "Insert `corfu-separator' or toggle escape if it's already there."
;; Otherwise, it does not insert the completion when +tng is enabled.
(interactive) (interactive)
(setq this-command #'corfu-insert-separator) (cond ((and (char-equal (char-before) corfu-separator)
(call-interactively #'corfu-insert-separator)) (char-equal (char-before (1- (point))) ?\\))
(save-excursion (delete-char -2)))
((char-equal (char-before) corfu-separator)
(save-excursion (backward-char 1)
(insert-char ?\\)))
(t
;; Without this corfu quits immediately.
(setq this-command #'corfu-insert-separator)
(call-interactively #'corfu-insert-separator))))

View file

@ -1,6 +1,6 @@
;;; completion/corfu/config.el -*- lexical-binding: t; -*- ;;; completion/corfu/config.el -*- lexical-binding: t; -*-
(defvar +cape-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-line' or `cape-dabbrev'. "Size limit for a buffer to be scanned by `cape-line' or `cape-dabbrev'.
As an exception, `cape-line' will also scan buffers with the same As an exception, `cape-line' will also scan buffers with the same
@ -9,71 +9,57 @@ major mode regardless of size.")
;; ;;
;;; Packages ;;; Packages
(use-package! corfu (use-package! corfu
:hook ((doom-first-buffer . global-corfu-mode) :hook ((doom-first-buffer . global-corfu-mode))
(org-mode . corfu-mode)) :config
:init
(when (modulep! +orderless)
(after! orderless
(setq orderless-component-separator #'orderless-escapable-split-on-space)))
;; Auto-completion settings, must be set before calling `global-corfu-mode'.
;; 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
corfu-separator ?\s global-corfu-modes '((not
corfu-excluded-modes '(erc-mode erc-mode
circe-mode circe-mode
help-mode help-mode
gud-mode gud-mode
vterm-mode)) vterm-mode)
;; `:g' is needed here to prevent `global-map' from overriding this with t)
;; `set-mark-command'. corfu-cycle t
(map! :unless (modulep! +tng) :gi "C-SPC" #'completion-at-point) corfu-separator (when (modulep! +orderless) ?\s)
:config corfu-preselect (if (modulep! +tng) 'prompt 'valid)
(setq corfu-cycle t
corfu-preselect (if (modulep! :completion corfu +tng) 'prompt t)
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 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; ;; In the case of +tng, TAB should be smart regarding completion;
;; 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))
(add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles)))
(defun corfu-disable-in-minibuffer-p () (map! :map corfu-mode-map
(or (bound-and-true-p mct--active) :eig "C-SPC" #'completion-at-point
(bound-and-true-p vertico--input) :mnor "C-SPC" (cmd! (call-interactively #'evil-insert-state)
(and (featurep 'helm-core) (helm--alive-p)) (call-interactively #'completion-at-point))
(eq (current-local-map) read-passwd-map))) :v "C-SPC" (cmd! (call-interactively #'evil-change)
(call-interactively #'completion-at-point)))
(defun corfu-enable-in-minibuffer () (defun +corfu-enable-in-minibuffer ()
"Enable Corfu in the minibuffer if `completion-at-point' is bound." "Enable Corfu in the minibuffer if `completion-at-point' is bound."
(unless (corfu-disable-in-minibuffer-p) (when (where-is-internal #'completion-at-point (list (current-local-map)))
(setq-local corfu-echo-delay nil ;; Disable automatic echo and popup (setq-local corfu-echo-delay nil)
corfu-popupinfo-delay nil)
(corfu-mode +1))) (corfu-mode +1)))
(add-hook 'minibuffer-setup-hook #'+corfu-enable-in-minibuffer)
(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 ;; If you want to update the visual hints after completing minibuffer commands
;; with Corfu and exiting, you have to do it manually. ;; with Corfu and exiting, you have to do it manually.
(defadvice! +corfu--insert-before-exit-minibuffer-a () (defadvice! +corfu--insert-before-exit-minibuffer-a ()
:before #'exit-minibuffer :before #'exit-minibuffer
(when (corfu-visible-p) (when (or (and (frame-live-p corfu--frame)
(frame-visible-p corfu--frame))
(and (featurep 'corfu-terminal)
(popon-live-p corfu-terminal--popon)))
(when (member isearch-lazy-highlight-timer timer-idle-list) (when (member isearch-lazy-highlight-timer timer-idle-list)
(apply (timer--function isearch-lazy-highlight-timer) (apply (timer--function isearch-lazy-highlight-timer)
(timer--args isearch-lazy-highlight-timer))) (timer--args isearch-lazy-highlight-timer)))
(when (member (bound-and-true-p anzu--update-timer) timer-idle-list) (when (member (bound-and-true-p anzu--update-timer) timer-idle-list)
;; Pending a PR I (@LemonBreezes) am making to expose `anzu--update-timer'.
(apply (timer--function anzu--update-timer) (apply (timer--function anzu--update-timer)
(timer--args anzu--update-timer))) (timer--args anzu--update-timer)))
(when (member (bound-and-true-p evil--ex-search-update-timer) (when (member (bound-and-true-p evil--ex-search-update-timer)
@ -81,202 +67,141 @@ major mode regardless of size.")
(apply (timer--function evil--ex-search-update-timer) (apply (timer--function evil--ex-search-update-timer)
(timer--args evil--ex-search-update-timer))))) (timer--args evil--ex-search-update-timer)))))
;; Allow completion after `:' in Lispy. (after! evil
(add-to-list 'corfu-auto-commands #'lispy-colon) (add-hook 'evil-insert-state-exit-hook #'corfu-quit))
(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))))
(when (modulep! +icons) (when (modulep! +icons)
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)) (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
(defun +corfu--reset-or-passthrough (cmd) (let ((cmds-del (cmds! (and (modulep! +tng)
(when (and (modulep! +tng) (> corfu--index -1)
(> corfu--index -1) (eq corfu-preview-current 'insert))
(eq corfu-preview-current 'insert)) #'corfu-reset)))
cmd))
(defun +corfu--backward-toggle-escape-sep (cmd)
(save-excursion
(backward-char 1)
(if (looking-back "\\\\" -1)
#'corfu-reset
(lambda ()
(interactive)
(save-excursion
(backward-char 1)
(insert-char ?\\))))))
(defun +corfu--insert-separator-or-toggle-escape (cmd)
(if (char-equal (char-before) corfu-separator)
(+corfu--backward-toggle-escape-sep cmd)
cmd))
(let ((mi-del '(menu-item "corfu-reset-or-passthrough" corfu-reset
:filter +corfu--maybe-reset-backspace-filter))
(mi-c-spc '(menu-item "corfu-insert-separator-or-toggle-escape" corfu-insert-separator
:filter +corfu--insert-separator-or-toggle-escape)))
(map! :map corfu-map (map! :map corfu-map
[return] #'corfu-insert [return] #'corfu-insert
"RET" #'corfu-insert "RET" #'corfu-insert
(:when (modulep! +orderless) (:when (modulep! +orderless)
:gi "C-SPC" mi-c-spc) "<remap> <completion-at-point>" #'+corfu-smart-sep-toggle-escape)
(:when (modulep! +tng) (:when (modulep! +tng)
[tab] #'corfu-next [tab] #'corfu-next
[backtab] #'corfu-previous [backtab] #'corfu-previous
"TAB" #'corfu-next "TAB" #'corfu-next
"S-TAB" #'corfu-previous "S-TAB" #'corfu-previous
[backspace] mi-del [backspace] cmds-del
"DEL" mi-del))) "DEL" cmds-del)))
(when (modulep! +orderless)
(after! orderless
(setq orderless-component-separator #'orderless-escapable-split-on-space)))
(after! vertico (after! vertico
(map! :map corfu-map (map! :map corfu-map
"M-m" #'corfu-move-to-minibuffer "M-m" #'+corfu-move-to-minibuffer
(:when (modulep! :editor evil) "M-J" #'corfu-move-to-minibuffer)))) (:when (modulep! :editor evil)
"M-J" #'+corfu-move-to-minibuffer))))
(use-package! cape (use-package! cape
:commands :defer t
cape-abbrev
cape-dabbrev
cape-dict
cape-elisp-block
cape-elisp-symbol
cape-emoji
cape-file
cape-history
cape-keyword
cape-line
cape-rfc1345
cape-sgml
cape-tex
cape-company-to-capf
cape-capf-super
cape-capf-buster
cape-capf-accept-all
cape-capf-debug
cape-capf-silent
cape-capf-purify
cape-capf-nonexclusive
cape-capf-noninterruptable
cape-capf-properties
cape-capf-predicate
cape-capf-prefix-length
cape-capf-inside-comment
cape-capf-inside-string
cape-capf-inside-faces
cape-capf-interactive
cape-wrap-buster
cape-wrap-accept-all
cape-wrap-debug
cape-wrap-silent
cape-wrap-purify
cape-wrap-nonexclusive
cape-wrap-noninterruptable
cape-wrap-properties
cape-wrap-predicate
cape-wrap-prefix-length
cape-wrap-inside-comment
cape-wrap-inside-string
cape-wrap-inside-faces
cape-interactive
:init :init
(add-hook! prog-mode (add-hook! prog-mode
(add-hook 'completion-at-point-functions #'cape-file -10 t)) (defun +corfu-add-cape-file-h ()
(add-hook 'completion-at-point-functions #'cape-file -10 t)))
(add-hook! (org-mode markdown-mode) (add-hook! (org-mode markdown-mode)
(add-hook 'completion-at-point-functions #'cape-elisp-block 0 t)) (defun +corfu-add-cape-elisp-block-h ()
(add-hook 'completion-at-point-functions #'cape-elisp-block 0 t)))
;; Enable Dabbrev completion basically everywhere as a fallback. ;; Enable Dabbrev completion basically everywhere as a fallback.
;; 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)
(when (modulep! +dabbrev) (when (modulep! +dabbrev)
(add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup ;; Set up `cape-dabbrev' options.
eshell-mode) (defun +dabbrev-friend-buffer-p (other-buffer)
(add-hook 'completion-at-point-functions #'cape-dabbrev 20 t))) (< (buffer-size other-buffer) +corfu-buffer-scanning-size-limit))
(after! dabbrev
(setq cape-dabbrev-check-other-buffers t
dabbrev-friend-buffer-function #'+dabbrev-friend-buffer-p
dabbrev-ignored-buffer-regexps
'("^ "
"\\(TAGS\\|tags\\|ETAGS\\|etags\\|GTAGS\\|GRTAGS\\|GPATH\\)\\(<[0-9]+>\\)?")
dabbrev-upcase-means-case-search t)
(add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode)
(add-hook! (prog-mode text-mode conf-mode comint-mode minibuffer-setup
;; Set up `cape-line' options. eshell-mode)
(defun +cape-line-buffers () (defun +corfu-add-cape-dabbrev-h ()
(cl-loop for buf in (buffer-list) (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t)))))
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)
(when (modulep! +line) (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) +corfu-buffer-scanning-size-limit))
collect buf))
(setq cape-line-buffer-function #'+cape-line-buffers)
(add-hook! (text-mode comint-mode minibuffer-setup) (add-hook! (text-mode comint-mode minibuffer-setup)
(add-hook 'completion-at-point-functions #'cape-line 20 t))) (defun +corfu-add-cape-line-h ()
(add-hook 'completion-at-point-functions #'cape-line 20 t))))
;; Complete emojis :). ;; Complete emojis :).
(when (and (modulep! +emoji) (> emacs-major-version 28)) (when (and (modulep! +emoji) (> emacs-major-version 28))
(add-hook! (prog-mode conf-mode) (add-hook! (prog-mode conf-mode)
(add-hook 'completion-at-point-functions (defun +corfu-add-cape-emoji-h ()
(cape-capf-inside-faces (add-hook 'completion-at-point-functions
(cape-capf-prefix-length #'cape-emoji 1) (cape-capf-inside-faces
;; Only call inside comments and docstrings. (cape-capf-prefix-length #'cape-emoji 1)
'tree-sitter-hl-face:doc 'font-lock-doc-face ;; Only call inside comments and docstrings.
'font-lock-comment-face 'tree-sitter-hl-face:comment) 'tree-sitter-hl-face:doc 'font-lock-doc-face
10 t)) 'font-lock-comment-face 'tree-sitter-hl-face:comment)
10 t)))
(add-hook! text-mode (add-hook! text-mode
(add-hook 'completion-at-point-functions (defun +corfu-add-cape-emoji-text-h ()
(cape-capf-prefix-length #'cape-emoji 1) 10 t))) (add-hook 'completion-at-point-functions
(cape-capf-prefix-length #'cape-emoji 1) 10 t))))
;; Enable dictionary-based autocompletion. ;; Enable dictionary-based autocompletion.
(when (modulep! +dict) (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! (prog-mode conf-mode)
(add-hook 'completion-at-point-functions (defun +corfu-add-cape-dict-h ()
(cape-capf-inside-faces (add-hook 'completion-at-point-functions
;; Only call inside comments and docstrings. (cape-capf-inside-faces
#'cape-dict 'tree-sitter-hl-face:doc 'font-lock-doc-face ;; Only call inside comments and docstrings.
'font-lock-comment-face 'tree-sitter-hl-face:comment) #'cape-dict 'tree-sitter-hl-face:doc 'font-lock-doc-face
40 t))) 'font-lock-comment-face 'tree-sitter-hl-face:comment)
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)
(advice-add #'eglot-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 #'lsp-completion-at-point :around #'cape-wrap-nonexclusive)
(advice-add #'pcomplete-completions-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 ;; From the `cape' readme. Without this, Eshell autocompletion is broken on
;; Emacs28. ;; Emacs28.
(when (< emacs-major-version 29) (when (< emacs-major-version 29)
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent) (advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify)) (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
:when (modulep! :editor snippets) :when (modulep! :editor snippets)
:defer t :defer t
:init :init
(add-hook! yas-minor-mode (add-hook! 'yas-minor-mode-hook
(add-hook 'completion-at-point-functions #'yasnippet-capf 30 t))) (defun +corfu-add-yasnippet-capf-h ()
(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))
:hook (corfu-mode . corfu-terminal-mode)) :hook ((corfu-mode . corfu-terminal-mode)))
;; ;;
;;; Extensions ;;; Extensions
(use-package! corfu-history (use-package! corfu-history
:hook (corfu-mode . corfu-history-mode) :hook ((corfu-mode . corfu-history-mode))
: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
(setq corfu-popupinfo-delay '(0.5 . 1.0)) (setq corfu-popupinfo-delay '(0.5 . 1.0))
(map! :map corfu-map (map! :map corfu-map

View file

@ -1,13 +1,12 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; completion/corfu/packages.el ;;; completion/corfu/packages.el
(package! corfu :recipe (:files ("*.el" "extensions/*.el")) :pin "457042d486e7542b9a6a832e47e6833d217ffd47") (package! corfu :pin "24dccafeea114b1aec7118f2a8405b46aa0051e0")
(package! cape :pin "abacb231157e0c90e29bdda6d15b4b448e48ffbd") (package! cape :pin "18a30f48bb8754421cb10dad99e0a406173d4551")
(when (modulep! +icons) (when (modulep! +icons)
(package! nerd-icons-completion :pin "c2db8557a3c1a9588d111f8c8e91cae96ee85010")
(package! nerd-icons-corfu :pin "7077bb76fefc15aed967476406a19dc5c2500b3c")) (package! nerd-icons-corfu :pin "7077bb76fefc15aed967476406a19dc5c2500b3c"))
(when (modulep! +orderless) (when (modulep! +orderless)
(package! orderless :pin "89eb3775daa53cfb52ad03015410c23f28c72d30")) (package! orderless :pin "b24748093b00b37c3a572c4909f61c08fa27504f"))
(when (modulep! :os tty) (when (modulep! :os tty)
(package! corfu-terminal :pin "501548c3d51f926c687e8cd838c5865ec45d03cc")) (package! corfu-terminal :pin "501548c3d51f926c687e8cd838c5865ec45d03cc"))
(when (modulep! :editor snippets) (when (modulep! :editor snippets)

View file

@ -6,7 +6,7 @@
:files ("*.el" "extensions/*.el")) :files ("*.el" "extensions/*.el"))
:pin "a28370d07f35c5387c7a9ec2e5b67f0d4598058d") :pin "a28370d07f35c5387c7a9ec2e5b67f0d4598058d")
(package! orderless :pin "89eb3775daa53cfb52ad03015410c23f28c72d30") (package! orderless :pin "b24748093b00b37c3a572c4909f61c08fa27504f")
(package! consult :pin "fe49dedd71802ff97be7b89f1ec4bd61b98c2b13") (package! consult :pin "fe49dedd71802ff97be7b89f1ec4bd61b98c2b13")
(package! consult-dir :pin "ed8f0874d26f10f5c5b181ab9f2cf4107df8a0eb") (package! consult-dir :pin "ed8f0874d26f10f5c5b181ab9f2cf4107df8a0eb")