emacs/lisp/acdw-consult.el

47 lines
1.5 KiB
EmacsLisp

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