From 33b646826b8a15744a6349196f77b654c8c96554 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 28 Jul 2021 12:53:02 -0400 Subject: [PATCH] fix(vertico): add counsel-file-jump analogue Fix 'SPC f F' / 'C-c f F' for vertico users --- core/autoload/projects.el | 4 ++-- .../completion/vertico/autoload/vertico.el | 22 +++++++++++++++++++ modules/config/default/autoload/files.el | 4 +--- modules/tools/lookup/autoload/lookup.el | 3 +++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/core/autoload/projects.el b/core/autoload/projects.el index 6346caf8d..fb7a81210 100644 --- a/core/autoload/projects.el +++ b/core/autoload/projects.el @@ -129,8 +129,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 'consult-find)) - (consult-find default-directory)) + (fboundp '+vertico/find-file-in)) + (+vertico/find-file-in default-directory)) ((and (bound-and-true-p ivy-mode) (fboundp 'counsel-file-jump)) (call-interactively #'counsel-file-jump)) diff --git a/modules/completion/vertico/autoload/vertico.el b/modules/completion/vertico/autoload/vertico.el index 2fc7c2930..f8dfa2a56 100644 --- a/modules/completion/vertico/autoload/vertico.el +++ b/modules/completion/vertico/autoload/vertico.el @@ -155,3 +155,25 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location (interactive) (vertico-previous (or n 1)) (+vertico/embark-preview)) + +(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) + (let* ((default-directory (or dir default-directory)) + (prompt-dir (consult--directory-prompt "Find" default-directory)) + (cmd (split-string-and-unquote consult-find-command " ")) + (cmd (remove "OPTS" cmd)) + (cmd (remove "ARG" cmd))) + (find-file + (consult--read + (split-string (cdr (apply #'doom-call-process cmd)) "\n" t) + :prompt default-directory + :sort nil + :require-match t + :initial (if initial (shell-quote-argument initial)) + :add-history (thing-at-point 'filename) + :category '+vertico + :history '(:input +vertico/find-file-in--history))))) diff --git a/modules/config/default/autoload/files.el b/modules/config/default/autoload/files.el index 9f21ed0c7..a50cc5674 100644 --- a/modules/config/default/autoload/files.el +++ b/modules/config/default/autoload/files.el @@ -34,9 +34,7 @@ (defun +default/find-file-under-here () "Perform a recursive file search from the current directory." (interactive) - (if (featurep! :completion ivy) - (call-interactively #'counsel-file-jump) - (doom-project-find-file default-directory))) + (doom-project-find-file default-directory)) ;;;###autoload (defun +default/discover-projects (arg) diff --git a/modules/tools/lookup/autoload/lookup.el b/modules/tools/lookup/autoload/lookup.el index 37c2744d4..1f9e9b2de 100644 --- a/modules/tools/lookup/autoload/lookup.el +++ b/modules/tools/lookup/autoload/lookup.el @@ -280,6 +280,9 @@ otherwise falling back to ffap.el (find-file-at-point)." ((and (featurep! :completion ivy) (doom-project-p)) (counsel-file-jump guess (doom-project-root))) + ((and (featurep! :completion vertico) + (doom-project-p)) + (+vertico/find-file-in (doom-project-root) guess)) ((find-file-at-point (ffap-prompter guess)))) t))