mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-03 05:26:18 +01:00
a5a651dbb9
Signed-off-by: main <magic_rb@redalder.org>
57 lines
2.1 KiB
Org Mode
57 lines
2.1 KiB
Org Mode
:PROPERTIES:
|
|
:ID: db1d0122-58d6-4dec-84f6-afcb52937fc7
|
|
:END:
|
|
#+title: Consult
|
|
#+filetags: emacs-load
|
|
|
|
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
|
|
#
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
#+BEGIN_QUOTE
|
|
Consult provides practical commands based on the Emacs completion function completing-read. Completion allows you to quickly select an item from a list of candidates.
|
|
#+END_QUOTE
|
|
|
|
#+BEGIN_SRC emacs-lisp :results none
|
|
(use-package consult
|
|
:straight t
|
|
:bind (("C-x b" . consult-buffer)
|
|
("C-x 4 b" . consult-buffer-other-window)
|
|
("C-x 5 b" . consult-buffer-other-frame)
|
|
;; M-s bindings (search-map)
|
|
("M-s r" . consult-ripgrep)
|
|
("M-s f" . consult-find))
|
|
:init
|
|
(setq consult-project-root-function #'projectile-project-root)
|
|
(setq consult-ripgrep-args "rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number --hidden .")
|
|
(setq consult-find-args "find ."))
|
|
#+END_SRC
|
|
|
|
Also enable ~fd~ support, as that ignores paths listed in .gitignore unlike ~find~..
|
|
|
|
#+begin_src emacs-lisp
|
|
(defvar consult--fd-command "fd")
|
|
(defun consult--fd-builder (input)
|
|
(unless consult--fd-command
|
|
(setq consult--fd-command
|
|
(if (eq 0 (call-process-shell-command "fdfind"))
|
|
"fdfind"
|
|
"fd")))
|
|
(pcase-let* ((`(,arg . ,opts) (consult--command-split input))
|
|
(`(,re . ,hl) (funcall consult--regexp-compiler
|
|
arg 'extended t)))
|
|
(when re
|
|
(list :command (append
|
|
(list consult--fd-command
|
|
"--color=never" "--full-path"
|
|
(consult--join-regexps re 'extended))
|
|
opts)
|
|
:highlight hl))))
|
|
|
|
(defun consult-fd (&optional dir initial)
|
|
(interactive "P")
|
|
(let* ((prompt-dir (consult--directory-prompt "Fd" dir))
|
|
(default-directory (cdr prompt-dir)))
|
|
(find-file (consult--find (car prompt-dir) #'consult--fd-builder initial))))
|
|
#+end_src
|