dotfiles/emacs/.emacs.d/config/init-completion.el
2021-07-27 11:50:02 -04:00

94 lines
2.9 KiB
EmacsLisp

;; -*- lexical-binding: t; -*-
;; Nicer minibuffer completion
;; First Selectrum, which provides the core incremental minibuffer completion engine
(use-package selectrum
:config
(selectrum-mode 1)
(leader-def-key "z" #'selectrum-repeat))
;; Then prescient, which adds the ability to sort and filter completions
(use-package selectrum-prescient
:after selectrum
:config
(selectrum-prescient-mode 1)
(prescient-persist-mode 1))
;; Marginalia adds annotations to completion candidates
(use-package marginalia
:demand t
:config
(marginalia-mode 1)
;; When using Selectrum, ensure that Selectrum is refreshed when cycling annotations.
(advice-add #'marginalia-cycle :after
(lambda ()
(when (bound-and-true-p selectrum-mode) (selectrum-exhibit))))
:general
(minibuffer-local-map "M-A" #'marginalia-cycle)
:custom
(marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil)))
;; Embark adds context actions to completion candidates
(use-package embark
:config
(defun embark-which-key-indicator (map _target)
(which-key--show-keymap "Embark" map nil nil 'no-paging)
#'which-key--hide-popup-ignore-command)
:general
("M-o" #'embark-act)
('normal embark-collect-mode-map
"TAB" #'forward-button
"?" #'describe-mode
"A" #'embark-collect-direct-action-minor-mode
"S" #'tabulated-list-sort
"a" #'embark-act
"b" #'backward-button
"e" #'embark-export
"f" #'forward-button
"gr" #'revert-buffer
"n" #'next-line
"p" #'previous-line
"q" #'quit-window
"s" #'isearch-forward
"v" #'embark-collect-toggle-view
"z" #'embark-collect-zebra-minor-mode
"{" #'tabulated-list-narrow-current-column
"}" #'tabulated-list-widen-current-column
"<backtab>" #'backward-button)
:custom
(embark-prompter 'embark-keymap-prompter)
(embark-indicator 'embark-which-key-indicator))
;; Consult adds a bunch of completing-read based utilities
(use-package consult
:commands (consult-xref)
:init
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
:custom
(consult-project-root-function #'projectile-project-root)
(consult-config '((consult-ripgrep :preview-key nil)
(consult-grep :preview-key nil)))
:general
([remap switch-to-buffer] #'consult-buffer)
([remap imenu] #'consult-imenu)
([remap projectile-ripgrep] #'consult-ripgrep)
([remap projectile-grep] #'consult-grep)
("C-c p" #'consult-yank))
(use-package consult-flycheck
:after flycheck
:general
(flycheck-command-map "!" #'consult-flycheck))
(use-package embark-consult
:defer 1)
;; Make grep-like embark collect buffers editable
(use-package wgrep
:general
(grep-mode-map "C-x C-q" #'wgrep-change-to-wgrep-mode))
(provide 'init-completion)