summaryrefslogtreecommitdiff
path: root/.config/emacs/modules/mm-completion.el
blob: 85763b7c4f38b4daeb0e5ecd0752967384e8e156 (plain) (blame)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;;; mm-completion.el --- Configuration for Emacs completion  -*- lexical-binding: t; -*-

^L
;;; Vertical Completions

(use-package vertico
  :ensure t
  :hook after-init
  :custom
  (vertico-cycle t)
  :config
  (require 'hl-line)
  ;; When working with ‘file-name-shadow-mode’ enabled, if I shadow old
  ;; input (i.e.) by typing ‘~/’ after ‘foo/bar’ Vertico will clear the
  ;; old path to keep only the current input (the old path is hidden by
  ;; ‘rfn-shadow’ anyways).
  (with-eval-after-load 'rfn-shadow
    (add-hook 'rfn-shadow-update-overlay-hook #'vertico-directory-tidy)))

^L
;;; Annotate Completions

;; TODO: Show git branch descriptions!
(use-package marginalia
  :ensure t
  :hook after-init
  :custom
  (marginalia-field-width 50)
  (marginalia-max-relative-age 0))

^L
;;; Minibuffer Completion Styles

(use-package minibuffer
  :bind ( :map minibuffer-local-completion-map
          ("SPC" . nil)
          ("?"   . nil))
  :custom
  (completion-styles '(basic substring orderless))
  (completion-category-defaults nil)    ; Avoid needing to override things
  (completion-category-overrides
   '((file             (styles . (basic partial-completion orderless)))
     (bookmark         (styles . (basic substring)))
     (library          (styles . (basic substring)))
     (imenu            (styles . (basic substring orderless)))
     (consult-location (styles . (basic substring orderless)))
     (kill-ring        (styles . (basic substring orderless)))))
  (completion-ignore-case t)
  (read-buffer-completion-ignore-case t)
  (read-file-name-completion-ignore-case t))

(use-package orderless
  :ensure t
  :after minibuffer
  :custom
  (orderless-matching-styles '(orderless-prefixes orderless-regexp)))

^L
;;; Disable Minibuffer Recursion Level

(use-package mb-depth
  :hook (after-init . minibuffer-depth-indicate-mode)
  :custom
  (enable-recursive-minibuffers t))

^L
;;; Don’t Show Defaults After Typing

;; Usually if a minibuffer prompt has a default value you can access by
;; hitting RET, the prompt will remain even if you begin typing (meaning
;; the default will no longer take effect on RET).  Enabling this mode
;; disables that behaviour.

(use-package minibuf-eldef
  :hook (after-init . minibuffer-electric-default-mode)
  :custom
  (minibuffer-default-prompt-format " [%s]"))

^L
;;; Hide Shadowed Filepaths

(use-package rfn-eshadow
  :hook (after-init . file-name-shadow-mode)
  :custom
  (file-name-shadow-properties '(invisible t intangilble t)))

^L
;;; Completion Popups

(use-package corfu
  :ensure t
  :hook prog-mode
  :bind ( :map corfu-map
          ("C-<return>" . newline))
  :custom
  (corfu-auto t)
  (corfu-cycle t)
  (corfu-auto-prefix 1)
  (corfu-auto-delay .1)
  (corfu-min-width 20)
  :config
  ;; I complete with RET and this interferes with ‘tempel-next’
  (keymap-unset corfu-map "TAB" :remove)
  (with-eval-after-load 'savehist
    (corfu-history-mode)
    (add-to-list 'savehist-additional-variables 'corfu-history)))

^L
;;; Save Minibuffer History

(use-package savehist-mode
  :hook (after-init . savehist-mode)
  :custom
  (history-length 200)
  (history-delete-duplicates t)
  :config
  (add-to-list 'savehist-additional-variables 'kill-ring))

^L
;;; Enhanced Replacements for Builtins

;; TODO: Investigate other commands
(use-package consult
  :ensure t
  :hook (completion-list-mode . consult-preview-at-point-mode)
  :bind ( ([remap switch-to-buffer] . consult-buffer)
          ([remap imenu]            . consult-imenu)
          ([remap goto-line]        . consult-goto-line)
          ("M-F"                    . consult-focus-lines)
          :map project-prefix-map
          ("b" . consult-project-buffer)
          :map consult-narrow-map
          ("?" . consult-narrow-help))
  :custom
  (consult-find-args
   (string-join
    '("find . -not ("
      "        -path '*/.git*'    -prune"
      "    -or -path '*/vendor/*' -prune"
      ")")
    " "))
  :config
  (with-eval-after-load 'pulsar
    (setopt consult-after-jump-hook nil)
    (dolist (command #'(pulsar-recenter-top pulsar-reveal-entry))
      (add-hook 'consult-after-jump-hook command))))

^L
;;; Dynamic Abbreviations

(use-package dabbrev
  :commands (dabbrev-completion dabbrev-expand)
  :custom
  (dabbrev-upcase-means-case-search t))

^L
;;; Finding Things

(use-package find-func
  :custom
  (find-library-include-other-files nil))

(provide 'mm-completion)