about summary refs log tree commit diff stats
path: root/lisp/acdw-consult.el
blob: 58a2136026f26fd1a235403d0d0282379e7ef3fd (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
;;; acdw-consult.el -*- lexical-binding: t; coding: utf-8-unix -*-

;; Customization for consult.

(require 'consult)

;; "Sensible" functions
(defun acdw-consult/sensible-grep (&optional arg)
  "Perform `consult-git-grep' if in a git project, otherwise `consult-ripgrep'
if ripgrep is installed, otherwise `consult-grep'."
  (interactive "P")
  (call-interactively
   (cond ((executable-find "rg")
          (if (fboundp 'affe-grep)
              #'affe-grep
            #'consult-ripgrep))
         ((string-equal (vc-backend buffer-file-name) "Git")
          #'consult-git-grep)
         (t #'consult-grep))))

(defun acdw-consult/sensible-find (&optional arg)
  "Peform `consult-locate' if locate is installed, otehrwise `consult-find'."
  (interactive "P")
  (call-interactively
   (cond ((executable-find "locate")
          #'consult-locate)
         ((fboundp 'affe-find)
          (when (executable-find "fd")
            (setq affe-find-command "fd -HI -t f"))
          #'affe-find)
         (t #'consult-find))))

;; Orderless Regexp Compiler! -- from Consult Wiki
(defun consult--orderless-regexp-compiler (input type)
  (setq input (orderless-pattern-compiler input))
  (cons
   (mapcar (lambda (r) (consult--convert-regexp r type)) input)
   (lambda (str) (orderless--highlight input str))))

(defun acdw-consult/complete-in-region (&rest args)
  (apply (if vertico-mode
             #'consult-completion-in-region
           #'completion--in-region)
         args))

(provide 'acdw-consult)