refactor(vertico): use consult-fd
Close: #7458 Co-authored-by: LemonBreezes <look@strawberrytea.xyz>
This commit is contained in:
parent
9bfc0ee029
commit
60e22fd2eb
4 changed files with 12 additions and 54 deletions
|
@ -150,8 +150,8 @@ If DIR is not a project, it will be indexed (but not cached)."
|
|||
#'counsel-projectile-find-file
|
||||
#'projectile-find-file)))
|
||||
((and (bound-and-true-p vertico-mode)
|
||||
(fboundp '+vertico/find-file-in))
|
||||
(+vertico/find-file-in default-directory))
|
||||
(fboundp '+vertico/consult-fd-or-find))
|
||||
(+vertico/consult-fd-or-find default-directory))
|
||||
((and (bound-and-true-p ivy-mode)
|
||||
(fboundp 'counsel-file-jump))
|
||||
(call-interactively #'counsel-file-jump))
|
||||
|
|
|
@ -137,26 +137,6 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
|
|||
(+vertico/embark-preview)
|
||||
(user-error (vertico-directory-enter)))))
|
||||
|
||||
(defvar +vertico/find-file-in--history nil)
|
||||
;;;###autoload
|
||||
(defun +vertico/find-file-in (&optional dir initial)
|
||||
"Jump to file under DIR (recursive).
|
||||
If INITIAL is non-nil, use as initial input."
|
||||
(interactive)
|
||||
(require 'consult)
|
||||
(let* ((default-directory (or dir default-directory))
|
||||
(prompt-dir (consult--directory-prompt "Find" default-directory))
|
||||
(cmd (split-string-and-unquote +vertico-consult-fd-args " ")))
|
||||
(find-file
|
||||
(consult--read
|
||||
(split-string (cdr (apply #'doom-call-process cmd)) "\n" t)
|
||||
:prompt default-directory
|
||||
:sort nil
|
||||
:initial (if initial (shell-quote-argument initial))
|
||||
:add-history (thing-at-point 'filename)
|
||||
:category 'file
|
||||
:history '(:input +vertico/find-file-in--history)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +vertico/jump-list (jump)
|
||||
"Go to an entry in evil's (or better-jumper's) jumplist."
|
||||
|
@ -229,27 +209,10 @@ targets."
|
|||
(not (string-suffix-p "-argument" (cdr binding))))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +vertico--consult--fd-make-builder ()
|
||||
(let ((cmd (split-string-and-unquote +vertico-consult-fd-args)))
|
||||
(lambda (input)
|
||||
(pcase-let* ((`(,arg . ,opts) (consult--command-split input))
|
||||
(`(,re . ,hl) (funcall consult--regexp-compiler
|
||||
arg 'extended t)))
|
||||
(when re
|
||||
(cons (append cmd
|
||||
(list (consult--join-regexps re 'extended))
|
||||
opts)
|
||||
hl))))))
|
||||
|
||||
(autoload #'consult--directory-prompt "consult")
|
||||
;;;###autoload
|
||||
(defun +vertico/consult-fd (&optional dir initial)
|
||||
(defun +vertico/consult-fd-or-find (&optional dir initial)
|
||||
(interactive "P")
|
||||
(if doom-projectile-fd-binary
|
||||
(pcase-let* ((`(,prompt ,paths ,dir) (consult--directory-prompt "Fd" dir))
|
||||
(default-directory dir)
|
||||
(builder (consult--find-make-builder paths)))
|
||||
(find-file (consult--find prompt builder initial)))
|
||||
(consult-fd dir initial)
|
||||
(consult-find dir initial)))
|
||||
|
||||
;;;###autoload
|
||||
|
|
|
@ -7,9 +7,6 @@ The completion/vertico module uses the orderless completion style by default,
|
|||
but this returns too broad a candidate set for company completion. This variable
|
||||
overrides `completion-styles' during company completion sessions.")
|
||||
|
||||
(defvar +vertico-consult-fd-args nil
|
||||
"Shell command and arguments the vertico module uses for fd.")
|
||||
|
||||
(defvar +vertico-consult-dir-container-executable "docker"
|
||||
"Command to call for listing container hosts.")
|
||||
|
||||
|
@ -149,13 +146,11 @@ orderless."
|
|||
consult-async-refresh-delay 0.15
|
||||
consult-async-input-throttle 0.2
|
||||
consult-async-input-debounce 0.1)
|
||||
(unless +vertico-consult-fd-args
|
||||
(setq +vertico-consult-fd-args
|
||||
(if doom-projectile-fd-binary
|
||||
(format "%s --color=never -i -H -E .git --regex %s"
|
||||
doom-projectile-fd-binary
|
||||
(if IS-WINDOWS "--path-separator=/" ""))
|
||||
consult-find-args)))
|
||||
(if doom-projectile-fd-binary
|
||||
(setq consult-fd-args
|
||||
'(doom-projectile-fd-binary
|
||||
"--full-path --color=never -i -H -E .git --regex"
|
||||
(when IS-WINDOWS "--path-separator=/"))))
|
||||
|
||||
(consult-customize
|
||||
consult-ripgrep consult-git-grep consult-grep
|
||||
|
@ -305,9 +300,9 @@ orderless."
|
|||
(map! (:map embark-file-map
|
||||
:desc "Open target with sudo" "s" #'doom/sudo-find-file
|
||||
(:when (modulep! :tools magit)
|
||||
:desc "Open magit-status of target" "g" #'+vertico/embark-magit-status)
|
||||
:desc "Open magit-status of target" "g" #'+vertico/embark-magit-status)
|
||||
(:when (modulep! :ui workspaces)
|
||||
:desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace))))
|
||||
:desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace))))
|
||||
|
||||
|
||||
(use-package! marginalia
|
||||
|
|
|
@ -283,7 +283,7 @@ otherwise falling back to ffap.el (find-file-at-point)."
|
|||
(counsel-file-jump guess (doom-project-root)))
|
||||
((and (modulep! :completion vertico)
|
||||
(doom-project-p))
|
||||
(+vertico/find-file-in (doom-project-root) guess))
|
||||
(+vertico/consult-fd-or-find (doom-project-root) guess))
|
||||
((find-file-at-point (ffap-prompter guess))))
|
||||
t))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue