emacs/lisp/acdw-consult.el

94 lines
3.2 KiB
EmacsLisp

;;; acdw-consult.el -*- lexical-binding: t; coding: utf-8-unix -*-
;; Customization for consult.
(require 'consult)
(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))
(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))))
;;; Circe buffers source
(require 'cl-lib)
(autoload 'circe-server-buffers "circe")
(autoload 'circe-server-chat-buffers "circe")
(defun circe-all-buffers ()
(cl-loop with servers = (circe-server-buffers)
for server in servers
collect server
nconc
(with-current-buffer server
(cl-loop for buf in (circe-server-chat-buffers)
collect buf))))
(defvar circe-buffer-source
`(:name "circe"
:hidden t
:narrow ?c
:category buffer
:state ,#'consult--buffer-state
:items ,(lambda () (mapcar #'buffer-name (circe-all-buffers)))))
(provide 'acdw-consult)