consult-dir icon indicating copy to clipboard operation
consult-dir copied to clipboard

How to integrate `consult-dir` (or `find-file`) with `consult-buffer`

Open vspinu opened this issue 2 years ago • 3 comments

This is what I would like to achieve:

  1. From consult-buffer invoke consult-dir
  2. Select directory
  3. Select file
  4. Open file directly, don't drop back to consult-buffer.

So basically I want consult-dir not to return to the original completion system but perform its normal action.

Maybe this can be achieved by default. It doesn't make much sense to insert the full path into consult-buffer interface. WDYT?

vspinu avatar Dec 18 '22 20:12 vspinu

BTW, if I invoke find-file from inside the consult-buffer I do get the file opened but the consult-buffer interface stays open, which is not ideal either.

vspinu avatar Dec 18 '22 20:12 vspinu

If you use Embark, the cleanest way to do this is to add consult-dir to embark-file+buffer-map and switch to consult-dir from consult-buffer using embark-become.

Besides the Embark approach I'm not sure of how to do this. consult-buffer and consult-dir are fundamentally different, incommensurate commands.

karthink avatar Feb 22 '23 07:02 karthink

This is a small quick hack that works for me:

(defvar rh-consult-dir--source-recentf
`(:name "Directory"
  :narrow ?d
  :category file
  :face consult-file
  :history file-name-history
  :action ,#'dired
  :state ,#'consult--file-preview
  :enabled ,(lambda () recentf-mode)
  :items ,#'consult-dir--recentf-dirs)
"Recentf directory source for `consult-buffer-sources'.")

(add-to-list 'consult-buffer-sources 'rh-consult-dir--source-recentf t)

ramblehead avatar Mar 14 '24 14:03 ramblehead