blob: 3a7ff281ada2a9a6c74a9d6b949822cf6c813fb6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
;;; 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
|