diff options
Diffstat (limited to 'lisp/+consult.el')
-rw-r--r-- | lisp/+consult.el | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lisp/+consult.el b/lisp/+consult.el new file mode 100644 index 0000000..7b6a20f --- /dev/null +++ b/lisp/+consult.el | |||
@@ -0,0 +1,47 @@ | |||
1 | ;;; +consult.el --- consult additions -*- lexical-binding: t -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (defun +consult-project-root () | ||
6 | "Return either the current project, or the VC root, of current file." | ||
7 | (if (and (functionp 'project-current) | ||
8 | (project-current)) | ||
9 | (car (project-roots (project-current))) | ||
10 | (vc-root-dir))) | ||
11 | |||
12 | ;;; Cribbed functions | ||
13 | ;; https://github.com/minad/consult/wiki | ||
14 | |||
15 | (defun consult--orderless-regexp-compiler (input type) | ||
16 | (setq input (orderless-pattern-compiler input)) | ||
17 | (cons | ||
18 | (mapcar (lambda (r) (consult--convert-regexp r type)) input) | ||
19 | (lambda (str) (orderless--highlight input str)))) | ||
20 | |||
21 | (defmacro consult-history-to-modes (map-hook-alist) | ||
22 | (let (defuns) | ||
23 | (dolist (map-hook map-hook-alist) | ||
24 | (let ((map-name (symbol-name (car map-hook))) | ||
25 | (key-defs `(progn (define-key | ||
26 | ,(car map-hook) | ||
27 | (kbd "M-r") | ||
28 | (function consult-history)) | ||
29 | (define-key ,(car map-hook) | ||
30 | (kbd "M-s") nil)))) | ||
31 | (push (if (cdr map-hook) | ||
32 | `(add-hook ',(cdr map-hook) | ||
33 | (defun | ||
34 | ,(intern (concat map-name | ||
35 | "@consult-history-bind")) | ||
36 | nil | ||
37 | ,(concat | ||
38 | "Bind `consult-history' to M-r in " | ||
39 | map-name ".\n" | ||
40 | "Defined by `consult-history-to-modes'.") | ||
41 | ,key-defs)) | ||
42 | key-defs) | ||
43 | defuns))) | ||
44 | `(progn ,@ (nreverse defuns)))) | ||
45 | |||
46 | (provide '+consult) | ||
47 | ;;; +consult.el ends here | ||