-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand file-name of consult-find target? #704
Comments
Huh, I thought we already did use full paths, but I guess that's just because |
Update: the problem seems specific to Vertico. When using the default completion framework, the above-named functions work as expected, because embark-target-guess-file-at-point finds the full file-path in the Completions buffer. So [edit: on further investigation, the proposed solution was /not/ advisable ;)] |
Revisiting this. The issue can be resolved by let-binding It's a bit convoluted, and a fair bit of code duplication, but these seem to do the trick: (defun embark--vertico-selected ()
"Target the currently selected item in Vertico.
Return the category metadatum as the type of the target."
(when vertico--input
(if-let* ((orig-base vertico--base)
(category (completion-metadata-get (embark--metadata) 'category))
(fn (lambda ()
;; Force candidate computation
(vertico--update)
(cons category (vertico--candidate))))
((equal vertico--base ""))
((eq 'file category))
(vertico--base
(abbreviate-file-name default-directory)))
(funcall fn)
(setq vertico--base orig-base)
(funcall fn))))
(defun embark--vertico-candidates ()
"Target the currently selected item in Vertico.
Return the category metadatum as the type of the target."
(when vertico--input
(if-let* ((orig-base vertico--base)
(category (completion-metadata-get (embark--metadata) 'category))
(fn (lambda ()
;; Force candidate computation
(vertico--update)
(cons category vertico--candidates)))
((equal vertico--base ""))
((eq 'file category))
(vertico--base
(abbreviate-file-name default-directory)))
(funcall fn)
(setq vertico--base orig-base)
(funcall fn)))) I couldn't think of any reason for patching this in Vertico or Consult instead, but maybe @minad would want to weigh in. |
@localauthor It doesn't look right to do this in the Vertico-specific functions. Also this looks way to complicated/hackish, and I hope we find a better way. Such transformations should better happen in some kind of transformer. But admittedly, I haven't fully understood the problem. |
I'll try to restate the problem. The functions When using Vertico and calling For many actions in A more compact solution would be to add a blanket (defun embark--simplify-path (_type target)
"Simplify and '//' or '~/' in the TARGET file path."
(cons 'file (abbreviate-file-name
(expand-file-name
(substitute-in-file-name target)))) |
I like that idea. I already have that |
The embark target returned when using
consult-find
is a partial file-path. In the example below, the target is the string "subdir1/subdir2/file1.org".This is a problem when using actions that do not include
expand-file-name
, such asembark-save-relative-path
andembark-insert-relative-path
. Also, when usingembark-insert
, only the target string is inserted, where the full file path might be expected (or desired, as in my case ;) ).Would it be warranted to expand the target to the full file name?
The text was updated successfully, but these errors were encountered: