;;; mf-completion.el --- Configuration for the completion framework -*- lexical-binding: t -*- ;;; Commentary: ;; Setup orderless, marginalia, consult and vertico for completions. ;;; Code: ;; Completion styles and interface (setq tab-always-indent 'complete) (mf/install orderless (setq orderless-component-separator "[ &]") (defun initialism-dispatcher (pattern index _total) "Orderless dispatcher to filter based on word initials." (if (string-suffix-p "," pattern) `(orderless-initialism . ,(substring pattern 0 -1)))) (defun basic-dispatcher (pattern index _total) "Orderless dispatcher for simple substring matching." (if (string-suffix-p "=" pattern) `(basic . ,(substring pattern 0 -1)))) (setq orderless-style-dispatchers '(initialism-dispatcher basic-dispatcher))) (mf/install marginalia) (marginalia-mode) (setq completion-styles '(orderless) completion-category-overrides '((file (styles partial-completion initials basic))) completions-format 'one-column completions-header-format nil completions-max-height 15 completion-auto-select nil completion-auto-wrap 'always completion-show-help nil) (mf/install vertico (setq vertico-cycle t vertico-count 15 completion-in-region-function (lambda (&rest args) (apply (if vertico-mode #'consult-completion-in-region #'completion--in-region) args))) (define-key vertico-map (kbd "M-DEL") #'vertico-directory-delete-char)) (vertico-mode) (mf/install cape) (add-to-list 'completion-at-point-functions #'cape-dabbrev) (add-to-list 'completion-at-point-functions #'cape-file) ;; Consult (mf/install consult (message "Loaded consult") (setq consult-narrow-key (kbd "<")) (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)) ;; keybindings (defun mf/one-theme (theme) "Disable all active themes and enable THEME." (when theme (unless (eq theme (car custom-enabled-themes)) (mapc #'disable-theme custom-enabled-themes) (if (custom-theme-p theme) (enable-theme theme) (load-theme theme t))))) (defun mf/consult-theme--or-switch (arg) "Switch or toggle theme. If called with a prefix ARG toggle between light and dark theme, otherwise execute `consult-theme'." (interactive "P") (if arg (let ((enabled-theme (car custom-enabled-themes))) (cond ((eq enabled-theme mf/light-theme) (mf/one-theme mf/dark-theme)) ((eq enabled-theme mf/dark-theme) (mf/one-theme mf/light-theme)) (t (mf/one-theme mf/light-theme)))) (call-interactively #'consult-theme))) (global-set-key (kbd "M-y") #'consult-yank-from-kill-ring) (global-set-key (kbd "C-x r b") #'consult-bookmark) (global-set-key (kbd "C-x b") #'consult-buffer) (global-set-key (kbd "C-x 4 b") #'consult-buffer-other-window) (global-set-key (kbd "C-x p b") #'consult-project-buffer) (global-set-key (kbd "M-g i") #'consult-imenu) (global-set-key (kbd "C-x C-SPC") #'consult-global-mark) (mf/leader "m" consult-man) (mf/leader "S" mf/consult-theme--or-switch) (mf/install company (defun just-one-face (fn &rest args) (let ((orderless-match-faces [completions-common-part])) (apply fn args))) (advice-add '-capf--candidates :around #'just-one-face)) (provide 'mf-completion) ;;; mf-completion.el ends here