this post was submitted on 29 Oct 2023
1 points (100.0% liked)

Emacs

305 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

Is there a solution for inserting a filename to a buffer (either to a normal buffer, or to the minibuffer) using a recursive fuzzy search, using the vertico + consult + corfu + cape ecosystem? Something like what consult-file does, but instead of opening the selected file, insert the path of it to a buffer.

We have cape-file, but it doesn't fuzzy search in a recursive way.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 10 months ago

For minibuffer completion, I created this, kind of works, but if there is an already developed, fully working solution, I'd rather use that. And I'm still interested in for a solution to use in a normal buffer that corfu could use.

(defun my-consult-fd-string (&optional dir initial)
  (interactive "P")
  (setq this-command 'consult-fd)
  (pcase-let* ((`(,prompt ,paths ,dir) (consult--directory-prompt "Fd" dir))
	   (default-directory dir)
	   (builder (consult--fd-make-builder paths)))
(concat dir (consult--find prompt builder initial))))

(defun my-consult-insert-fd-string ()
  (interactive)
  (insert
   (abbreviate-file-name
(let ((f (bounds-of-thing-at-point 'filename)))
  (if f
      (let ((r (my-consult-fd-string (buffer-substring-no-properties (car f) (cdr f)) nil)))
	(delete-region (car f) (cdr f))
	r)
    (my-consult-fd-string t nil))))))
(define-key minibuffer-local-map (kbd "M-f") 'my-consult-insert-fd-string)