diff options
Diffstat (limited to 'lisp/+orderless.el')
-rw-r--r-- | lisp/+orderless.el | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lisp/+orderless.el b/lisp/+orderless.el new file mode 100644 index 0000000..b2f53b0 --- /dev/null +++ b/lisp/+orderless.el | |||
@@ -0,0 +1,60 @@ | |||
1 | ;;; +orderless.el --- Mostly from minad -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; See https://github.com/minad/consult/wiki#minads-orderless-configuration | ||
6 | |||
7 | ;;; Code: | ||
8 | |||
9 | (require 'orderless) | ||
10 | |||
11 | ;;; Dispataching | ||
12 | |||
13 | (defvar +orderless-dispatch-alist '((?% . char-fold-to-regexp) | ||
14 | (?! . orderless-without-literal) | ||
15 | (?` . orderless-initialism) | ||
16 | (?= . orderless-literal) | ||
17 | (?~ . orderless-flex)) | ||
18 | "Charcters to dispatch styles on orderless segments.") | ||
19 | |||
20 | (defun +orderless-dispatch (pattern index _total) | ||
21 | "Dispatch orderless segments of a search string. | ||
22 | Dispatchers are taken from `+orderless-dispatch-alist', and added | ||
23 | to the following defaults: | ||
24 | |||
25 | - regexp$ :: matches REGEXP at the end of the pattern. | ||
26 | - .ext :: matches EXT (at end of pattern) | ||
27 | |||
28 | Dispatch characters can be added at the beginning or ending of a | ||
29 | segment to make that segment match accordingly." | ||
30 | (cond | ||
31 | ;; Ensure that $ works with Consult commands, which add disambiguation | ||
32 | ;; suffixes | ||
33 | ((string-suffix-p "$" pattern) | ||
34 | (cons 'orderless-regexp | ||
35 | (concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$"))) | ||
36 | ;; File extensions | ||
37 | ((and | ||
38 | ;; Completing filename or eshell | ||
39 | (or minibuffer-completing-file-name | ||
40 | (derived-mode-p 'eshell-mode)) | ||
41 | ;; File extension | ||
42 | (string-match-p "\\`\\.." pattern)) | ||
43 | (cons orderless-regexp | ||
44 | (concat "\\." (substring pattern 1) "[\x100000-\x10FFFD]*$"))) | ||
45 | ;; Ignore single ! | ||
46 | ((string= "!" pattern) `(orderless-literal . "")) | ||
47 | ;; Prefix and suffix | ||
48 | ((if-let (x (assq (aref pattern 0) +orderless-dispatch-alist)) | ||
49 | (cons (cdr x) (substring pattern 1)) | ||
50 | (when-let (x (assq (aref pattern (1- (length pattern))) | ||
51 | +orderless-dispatch-alist)) | ||
52 | (cons (cdr x) (substring pattern 0 -1))))))) | ||
53 | |||
54 | (orderless-define-completion-style +orderless-with-initialism | ||
55 | (orderless-matching-styles '(orderless-initialism | ||
56 | orderless-literal | ||
57 | orderless-regexp))) | ||
58 | |||
59 | (provide '+orderless) | ||
60 | ;;; +orderless.el ends here | ||