Archived
124 lines
2.6 KiB
EmacsLisp
Executable File
124 lines
2.6 KiB
EmacsLisp
Executable File
;;; init-completion.el --- Minibuffer + in-buffer completion -*- lexical-binding: t; -*-
|
|
|
|
;;; Commentary:
|
|
;; Vertico + Orderless + Marginalia + Consult for minibuffer completion.
|
|
;; Corfu provides in-buffer completion.
|
|
;; Embark adds contextual actions.
|
|
|
|
;;; Code:
|
|
|
|
;;;; Helper functions
|
|
|
|
(defun my/find-file-below (file)
|
|
"Open FILE in a split below."
|
|
(interactive "fFile: ")
|
|
(select-window (split-window-below))
|
|
(find-file file))
|
|
|
|
(defun my/find-file-right (file)
|
|
"Open FILE in a split to the right."
|
|
(interactive "fFile: ")
|
|
(select-window (split-window-right))
|
|
(find-file file))
|
|
|
|
(defun my/vertico-split-below ()
|
|
"Open the selected Vertico file candidate below."
|
|
(interactive)
|
|
(setq unread-command-events (listify-key-sequence "2"))
|
|
(embark-act))
|
|
|
|
(defun my/vertico-split-right ()
|
|
"Open the selected Vertico file candidate to the right."
|
|
(interactive)
|
|
(setq unread-command-events (listify-key-sequence "3"))
|
|
(embark-act))
|
|
|
|
;;;; Vertico
|
|
|
|
(use-package vertico
|
|
:init
|
|
(vertico-mode)
|
|
|
|
:custom
|
|
(vertico-count 25))
|
|
|
|
(use-package vertico-posframe
|
|
:after vertico
|
|
:custom
|
|
(vertico-posframe-poshandler #'posframe-poshandler-frame-center)
|
|
(vertico-posframe-border-width 2)
|
|
(vertico-posframe-width 120)
|
|
(vertico-posframe-max-width 300)
|
|
:config
|
|
(vertico-posframe-mode))
|
|
|
|
;;;; Completion styles
|
|
|
|
(use-package orderless
|
|
:custom
|
|
(completion-styles '(orderless basic))
|
|
(completion-category-defaults nil)
|
|
(completion-category-overrides
|
|
'((file (styles partial-completion)))))
|
|
|
|
(use-package marginalia
|
|
:init
|
|
(marginalia-mode))
|
|
|
|
;;;; In-buffer completion
|
|
|
|
(use-package corfu
|
|
:init
|
|
(global-corfu-mode)
|
|
|
|
:custom
|
|
(corfu-auto t)
|
|
(corfu-auto-delay 0.15)
|
|
(corfu-auto-prefix 2)
|
|
(corfu-cycle t)
|
|
(corfu-preselect 'first)
|
|
|
|
:bind
|
|
(:map corfu-map
|
|
("C-n" . corfu-next)
|
|
("C-p" . corfu-previous)
|
|
("RET" . corfu-insert)
|
|
("<escape>" . corfu-quit))
|
|
|
|
:config
|
|
(with-eval-after-load 'evil
|
|
(evil-define-key 'insert 'global
|
|
(kbd "C-n") #'corfu-next
|
|
(kbd "C-p") #'corfu-previous)))
|
|
|
|
;;;; Minibuffer commands
|
|
|
|
(use-package consult)
|
|
|
|
;;;; Contextual actions
|
|
|
|
(use-package embark
|
|
:after vertico
|
|
:bind
|
|
(("C-." . embark-act)
|
|
:map embark-file-map
|
|
("2" . my/find-file-below)
|
|
("3" . my/find-file-right)
|
|
:map vertico-map
|
|
("C-s" . my/vertico-split-below)
|
|
("C-v" . my/vertico-split-right)))
|
|
|
|
(use-package embark-consult
|
|
:after (embark consult)
|
|
:hook
|
|
(embark-collect-mode . consult-preview-at-point-mode))
|
|
|
|
;;;; Help/discovery
|
|
|
|
(use-package which-key
|
|
:config
|
|
(which-key-mode))
|
|
|
|
(provide 'init-completion)
|
|
;;; init-completion.el ends here
|