aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-completion.el
blob: 1199f4b54f4cfe5f8fd2f9389bde68d17cc526d6 (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
(when (gx/maybe-require-package 'orderless)

  (require 'orderless)

  (setq orderless-matching-styles
        '(orderless-literal orderless-regexp orderless-prefixes))

  (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))

  (setq completion-styles '(substring orderless flex)
        completion-category-defaults nil
        completion-category-overrides
        '((file (styles . (partial-completion))))))

(when (gx/maybe-require-package 'cape)
  (autoload #'cape-file "cape")
  (add-to-list 'completion-at-point-functions #'cape-file))

(provide 'init-completion)