summaryrefslogtreecommitdiff
path: root/dot_config/emacs/lisp/completion-config.el
diff options
context:
space:
mode:
authorSakamoto <me@sakamoto.network>2026-08-16 15:34:00 -0500
committerSakamoto <me@sakamoto.network>2026-08-16 15:34:00 -0500
commitd51beea88d300cb5066bb92a8148cad52fa1091d (patch)
tree4357b4958c19dddd304a0d6ee77994fb9f12c118 /dot_config/emacs/lisp/completion-config.el
parenta623fed63460d6d810605ce1ce858a58a5b222f7 (diff)
downloaddotfiles-d51beea88d300cb5066bb92a8148cad52fa1091d.tar.xz
dotfiles-d51beea88d300cb5066bb92a8148cad52fa1091d.zip
update
Diffstat (limited to 'dot_config/emacs/lisp/completion-config.el')
-rw-r--r--dot_config/emacs/lisp/completion-config.el104
1 files changed, 104 insertions, 0 deletions
diff --git a/dot_config/emacs/lisp/completion-config.el b/dot_config/emacs/lisp/completion-config.el
new file mode 100644
index 0000000..75c184a
--- /dev/null
+++ b/dot_config/emacs/lisp/completion-config.el
@@ -0,0 +1,104 @@
+;; Modern interactive completion framework for the minibuffer
+(use-package vertico
+ :hook
+ (after-init . vertico-mode) ;; Enable vertico after Emacs has initialized.
+ :custom
+ (vertico-cycle nil) ;; Do not cycle through candidates when reaching the end of the list.
+ :config
+ ;; Customize the display of the current candidate in the completion list.
+ ;; This will prefix the current candidate with “» ” to make it stand out.
+ ;; Reference: https://github.com/minad/vertico/wiki#prefix-current-candidate-with-arrow
+ (advice-add #'vertico--format-candidate :around
+ (lambda (orig cand prefix suffix index _start)
+ (setq cand (funcall orig cand prefix suffix index _start))
+ (concat
+ (if (= vertico--index index)
+ (propertize "» " 'face '(:foreground "#80adf0" :weight bold))
+ " ")
+ cand))))
+
+(use-package which-key
+ :ensure nil
+ :config
+ (which-key-mode 1))
+
+(use-package orderless
+ :defer t ;; Load Orderless on demand.
+ :after vertico ;; Ensure Vertico is loaded before Orderless.
+ :init
+ (setq completion-styles '(orderless basic) ;; Set the completion styles.
+ completion-category-defaults nil ;; Clear default category settings.
+ completion-category-overrides '((file (styles partial-completion))))) ;; Customize file completion styles.
+
+;; Marginalia enhances the completion experience in Emacs by adding
+;; additional context to the completion candidates. This includes
+;; helpful annotations such as documentation and other relevant
+;; information, making it easier to choose the right option.
+(use-package marginalia
+ :hook
+ (after-init . marginalia-mode))
+
+;;; CONSULT
+;; Consult provides powerful completion and narrowing commands for Emacs.
+;; It integrates well with other completion frameworks like Vertico, enabling
+;; features like previews and enhanced register management. It's useful for
+;; navigating buffers, files, and xrefs with ease.
+(use-package consult
+ :ensure t
+ :defer t
+ :init
+ ;; Enhance register preview with thin lines and no mode line.
+ (advice-add #'register-preview :override #'consult-register-window)
+
+ ;; Use Consult for xref locations with a preview feature.
+ (setq xref-show-xrefs-function #'consult-xref
+ xref-show-definitions-function #'consult-xref)
+
+ :bind (;; C-x bindings in `ctl-x-map'
+ ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
+ ("C-x b" . consult-buffer) ;; orig. switch-to-buffer
+ ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
+ ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
+ ("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab
+ ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
+ ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
+ ;; Custom M-# bindings for fast register access
+ ("M-#" . consult-register-load)
+ ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
+ ("C-M-#" . consult-register)
+ ;; Other custom bindings
+ ("M-y" . consult-yank-pop) ;; orig. yank-pop
+ ;; M-g bindings in `goto-map'
+ ("M-g e" . consult-compile-error)
+ ("M-g r" . consult-grep-match)
+ ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
+ ("M-g g" . consult-goto-line) ;; orig. goto-line
+ ("M-g M-g" . consult-goto-line) ;; orig. goto-line
+ ("M-g o" . consult-outline) ;; Alternative: consult-org-heading
+ ("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) ;; Alternative: consult-fd
+ ("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) ;; orig. isearch-edit-string
+ ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
+ ("M-s l" . consult-line) ;; needed by consult-line to detect isearch
+ ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch
+ ;; Minibuffer history
+ :map minibuffer-local-map
+ ("M-s" . consult-history) ;; orig. next-matching-history-element
+ ("M-r" . consult-history))) ;; orig. previous-matching-history-element
+
+(provide 'completion-config)