Skip to content

Commit

Permalink
fix(vertico): add counsel-file-jump analogue
Browse files Browse the repository at this point in the history
Fix 'SPC f F' / 'C-c f F' for vertico users
  • Loading branch information
hlissner committed Jul 28, 2021
1 parent 551e5ad commit 33b6468
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/autoload/projects.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 22 additions & 0 deletions modules/completion/vertico/autoload/vertico.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
4 changes: 1 addition & 3 deletions modules/config/default/autoload/files.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions modules/tools/lookup/autoload/lookup.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 33b6468

Please sign in to comment.