;;; 10-completion.el --- Setup completion. -*- no-byte-compile: t; lexical-binding: t; -*- ;;; Description: ;; This file contains code setting up all the completion packages, ;; such as corfu, vertico, marginalia, orderless, etc. ;;; Code: ;; This package provides marginalia-mode which adds marginalia to the ;; minibuffer completions. Marginalia are marks or annotations placed ;; at the margin of the page of a book or in this case helpful ;; colorful annotations placed at the margin of the minibuffer for ;; your completion candidates. (use-package marginalia ;; Marginalia allows Embark to offer you preconfigured actions in more contexts. ;; In addition to that, Marginalia also enhances Vertico by adding rich ;; annotations to the completion candidates displayed in Vertico's interface. :ensure t :defer t :commands (marginalia-mode marginalia-cycle) :hook (after-init . marginalia-mode) :init (define-key minibuffer-local-map "\M-A" 'marginalia-cycle)) ;; Emacs Mini-Buffer Actions Rooted in Keymaps. Embark makes it easy ;; to choose a command to run based on what is near point, both during ;; a minibuffer completion session (in a way familiar to Helm or ;; Counsel users) and in normal buffers. (use-package embark ;; Embark is an Emacs package that acts like a context menu, allowing ;; users to perform context-sensitive actions on selected items ;; directly from the completion interface. :ensure t :defer t :commands (embark-act embark-dwim embark-export embark-collect embark-bindings embark-prefix-help-command) :bind (("C-." . embark-act) ;; pick some comfortable binding ("C-;" . embark-dwim) ;; good alternative: M-. ("C-h B" . embark-bindings) ;; alternative for `describe-bindings' :map embark-flymake-map ("a" . eglot-code-actions)) :init (setq prefix-help-command #'embark-prefix-help-command) :config ;; Hide the mode line of the Embark live/completions buffers (add-to-list 'display-buffer-alist '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" nil (window-parameters (mode-line-format . none)))) (push 'embark--allow-edit (alist-get 'eglot-code-actions embark-target-injection-hooks)) (push 'embark--ignore-target (alist-get 'eglot-code-actions embark-target-injection-hooks))) ;; This package provides some integrations between the emabrk and ;; consult packages. (use-package embark-consult :ensure t :hook (embark-collect-mode . consult-preview-at-point-mode)) ;; Consulting completing-read. Consult provides search and navigation ;; commands based on the Emacs completion function ;; completing-read. Completion allows you to quickly select an item ;; from a list of candidates. (use-package consult :ensure t :bind (;; C-c bindings in `mode-specific-map' ("C-c M-x" . consult-mode-command) ("C-c C-h" . consult-history) ("C-c k" . consult-kmacro) ("C-c m" . consult-man) ("C-c i" . consult-info) ([remap Info-search] . consult-info) ;; C-x bindings in `ctl-x-map' ("C-x M-:" . consult-complex-command) ("C-x b" . consult-buffer) ("C-x 4 b" . consult-buffer-other-window) ("C-x 5 b" . consult-buffer-other-frame) ("C-x t b" . consult-buffer-other-tab) ("C-x r b" . consult-bookmark) ("C-x p b" . consult-project-buffer) ;; Custom M-# bindings for fast register access ("M-#" . consult-register-load) ("M-'" . consult-register-store) ("C-M-#" . consult-register) ;; Other custom bindings ("M-y" . consult-yank-pop) ;; M-g bindings in `goto-map' ("M-g e" . consult-compile-error) ("M-g f" . consult-flymake) ("M-g g" . consult-goto-line) ("M-g M-g" . consult-goto-line) ("M-g o" . consult-outline) ("M-g m" . consult-mark) ("M-g k" . consult-global-mark) ("M-g i" . consult-imenu) ("M-g I" . consult-imenu-multi) ;; M-s bindings in `search-map' ("M-s d" . consult-find) ("M-s c" . consult-locate) ("M-s g" . consult-grep) ("M-s G" . consult-git-grep) ("M-s r" . consult-ripgrep) ("M-s l" . consult-line) ("M-s L" . consult-line-multi) ("M-s k" . consult-keep-lines) ("M-s u" . consult-focus-lines) ;; Isearch integration ("M-s e" . consult-isearch-history) :map isearch-mode-map ("M-e" . consult-isearch-history) ("M-s e" . consult-isearch-history) ("M-s l" . consult-line) ("M-s L" . consult-line-multi) ;; Minibuffer history :map minibuffer-local-map ("M-s" . consult-history) ("M-r" . consult-history)) ;; Enable automatic preview at point in the *Completions* buffer. :hook (completion-list-mode . consult-preview-at-point-mode) :init ;; Optionally configure the register formatting. This improves the register (setq register-preview-delay 0.5 register-preview-function #'consult-register-format) ;; Optionally tweak the register preview window. (advice-add #'register-preview :override #'consult-register-window) ;; Use Consult to select xref locations with preview (setq xref-show-xrefs-function #'consult-xref xref-show-definitions-function #'consult-xref) :config (consult-customize consult-theme :preview-key '(:debounce 0.2 any) consult-ripgrep consult-git-grep consult-grep consult-bookmark consult-recent-file consult-xref consult-source-bookmark consult-source-file-register consult-source-recent-file consult-source-project-recent-file ;; :preview-key "M-." :preview-key '(:debounce 0.4 any)) (setq consult-narrow-key "<")) (setq tab-always-indent 'complete) ;; Starts completion with TAB (fido-mode -1) (icomplete-mode) (icomplete-vertical-mode) (setq icomplete-delay-completions-threshold 0) (setq icomplete-compute-delay 0) (setq icomplete-show-matches-on-no-input t) (setq icomplete-hide-common-prefix nil) (setq icomplete-prospects-height 10) (setq icomplete-separator " . ") (setq icomplete-with-completion-tables t) (setq icomplete-max-delay-chars 0) (setq icomplete-scroll t) (keymap-set icomplete-minibuffer-map "TAB" 'icomplete-force-complete) (keymap-set icomplete-minibuffer-map "RET" 'icomplete-force-complete-and-exit) (keymap-set icomplete-minibuffer-map "C-" 'icomplete-fido-exit) (setq completion-styles '(basic partial-completion initials flex emacs22)) (setq completion-auto-select t) ;; Show completion on first call (setq completion-auto-help 'visible) ;; Display *Completions* upon first request (setq completions-format 'one-column) ;; Use only one column (setq completions-sort 'historical) ;; Order based on minibuffer history (setq completions-max-height 15) ;; Limit completions to 10 (completions start at line 5) (setq completion-ignore-case t) ;;; 10-completion.el ends here