karthink / consult-dir

Insert paths into the minibuffer prompt in Emacs
GNU General Public License v3.0
160 stars 9 forks source link

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

Open vspinu opened 1 year ago

vspinu commented 1 year ago

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 commented 1 year ago

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.

karthink commented 1 year ago

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.

ramblehead commented 7 months ago

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)