aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-minibuffer.el
blob: c9cb86f9c0a916dcee0b3422b33adccee6755bb8 (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
;; -*- lexical-binding: t -*-

(gx/maybe-require-package 'consult)

(when (gx/maybe-require-package 'vertico)
  (add-hook 'after-init-hook #'vertico-mode))

(setq vertico-resize t
      vertico-count 20
      vertico-cycle t)

(setq completion-ignore-case t
      read-file-name-completion-ignore-case t
      read-buffer-completion-ignore-case t)

(with-eval-after-load 'vertico
  (define-key vertico-map (kbd "C-c j") 'vertico-quick-jump)
  (define-key vertico-map (kbd "C-c C-j") 'vertico-quick-jump)
  (define-key vertico-map (kbd "C-d")
              (lambda () (interactive) (vertico-next (/ vertico-count 2))))
  (define-key vertico-map (kbd "C-u")
              (lambda () (interactive) (vertico-previous (/ vertico-count 2)))))

(when (gx/maybe-require-package 'orderless)
  (setq orderless-matching-styles '(orderless-literal orderless-regexp))

  (defun gx/orderless-without-if-bang (pattern _index _total)
    (cond
     ((equal "!" pattern)
      '(orderless-literal . ""))
     ((string-prefix-p "!" pattern)
      `(orderless-without-literal . ,(substring pattern 1)))))

  (defun gx/orderless-flex-if-twiddle (pattern _index _total)
    (when (string-suffix-p "~" pattern)
      `(orderless-flex . ,(substring pattern 0 -1))))

  (setq orderless-style-dispatchers '(gx/orderless-without-if-bang
                                      gx/orderless-flex-if-twiddle))

  (defun gx/setup-completion-in-minibuffer ()
    (setq-local completion-styles '(substring orderless)
                completion-category-defaults nil
                completion-category-overrides '((file (styles partial-completion)))))
  (add-hook 'minibuffer-setup-hook #'gx/setup-completion-in-minibuffer))

(when (gx/maybe-require-package 'consult)
  (with-eval-after-load 'evil
    (evil-define-key 'normal 'global
      (kbd "<leader>fb") 'consult-buffer
      (kbd "<leader>fm") 'consult-recent-file
      (kbd "<leader>fc") 'execute-extended-command
      (kbd "<leader>fl") 'consult-line
      (kbd "<leader>fs") 'consult-imenu
      (kbd "<leader>fa") 'consult-org-agenda)
    (evil-define-key 'normal 'eglot--managed-mode
      (kbd "<leader>fS") 'consult-eglot-symbols)))

(when (executable-find "rg")
  (setq affe-grep-command
        "rg --null --line-buffered --color=never --max-columns=1000 \
--path-separator / -v ^$ \
--smart-case --no-heading --line-number --hidden --glob !.git ."))

(when (executable-find "fd")
  (setq affe-find-command
        "fd --type f --hidden --follow --exclude .git"))

(when (gx/maybe-require-package 'affe)
  (with-eval-after-load 'evil
    (evil-define-key 'normal 'global
      (kbd "<leader>ff") 'affe-find
      (kbd "<leader>fr") 'affe-grep))
  (with-eval-after-load 'orderless
    (defun gx/affe-orderless-regexp-compiler (input _type _ignorecase)
      (setq input (orderless-pattern-compiler input))
      (cons input (lambda (str) (orderless--highlight input str))))
    (setq affe-regexp-compiler #'gx/affe-orderless-regexp-compiler))
  (with-eval-after-load 'consult
    (consult-customize
     affe-grep affe-find
     :preview-key (kbd "C-c C-p"))))

(setq consult-preview-key (kbd "C-c C-p"))

(when (gx/maybe-require-package 'savehist)
  (add-hook 'after-init-hook #'savehist-mode))

(provide 'init-minibuffer)