about summary refs log tree commit diff stats
path: root/lisp/+consult.el
blob: 21c2565878caf77c37d097e579985a2dd644a277 (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
;;; +consult.el --- consult additions -*- lexical-binding: t -*-

;;; Code:

(defun +consult-project-root ()
  "Return either the current project, or the VC root, of current file."
  (if (and (functionp 'project-current)
           (project-current))
      (car (project-roots (project-current)))
    (vc-root-dir)))

;;; Cribbed functions
;; https://github.com/minad/consult/wiki

(defun consult--orderless-regexp-compiler (input type &rest _)
  (setq input (orderless-pattern-compiler input))
  (cons
   (mapcar (lambda (r) (consult--convert-regexp r type)) input)
   (lambda (str) (orderless--highlight input str))))

(defmacro consult-history-to-modes (map-hook-alist)
  (let (defuns)
    (dolist (map-hook map-hook-alist)
      (let ((map-name (symbol-name (car map-hook)))
            (key-defs `(progn (define-key
                                ,(car map-hook)
                                (kbd "M-r")
                                (function consult-history))
                              (define-key ,(car map-hook)
                                (kbd "M-s") nil))))
        (push (if (cdr map-hook)
                  `(add-hook ',(cdr map-hook)
                             (defun
                                 ,(intern (concat map-name
                                                  "@consult-history-bind"))
                                 nil
                               ,(concat
                                 "Bind `consult-history' to M-r in "
                                 map-name ".\n"
                                 "Defined by `consult-history-to-modes'.")
                               ,key-defs))
                key-defs)
              defuns)))
    `(progn ,@ (nreverse defuns))))

(provide '+consult)
;;; +consult.el ends here