Skip to content
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

find-file selects first candidate when on tramp home dir #193

Closed
ghost opened this issue Feb 3, 2022 · 4 comments
Closed

find-file selects first candidate when on tramp home dir #193

ghost opened this issue Feb 3, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 3, 2022

So I've looked at these issues: #192 #156

And it looks like find-file completion should initially select the prompt if "the prompt shows a complete and valid file path". However, when connecting to a remote host, this leads to a path such as: /ssh:user@hostname:~/ which I guess is not considered "complete and valid file path" for some reason?

Personally when it comes to find-file I always want the prompt to be initially selected to take advantage of vertico-directory-tidy at all times. Which makes me wonder why there's the conditional of if "the prompt shows a complete and valid file path". When would that not be the case? Doesn't find-file always have the current directory as the prompt which means it's always complete and valid?

@minad
Copy link
Owner

minad commented Feb 3, 2022

https://github.com/minad/vertico/issues/156And it looks like find-file completion should initially select the prompt if "the prompt shows a complete and valid file path". However, when connecting to a remote host, this leads to a path such as: /ssh:user@hostname:~/ which I guess is not considered "complete and valid file path" for some reason?

This seems indeed to be the case. I assume the problem is the same as in #174. The file completion table reports a wrong completion boundary. See the bug I've reported https://debbugs.gnu.org/cgi/bugreport.cgi?bug=53053. Maybe it is not exactly this issue but it is at least related. The issue is an edge case, so I assume it is considered low priority by upstream and not yet fixed there.

Personally when it comes to find-file I always want the prompt to be initially selected to take advantage of vertico-directory-tidy at all times.

vertico-directory-tidy has nothing to do with if the prompt is selected or not. It will always cleanup the prompt if registered as hook.

Which makes me wonder why there's the conditional of if "the prompt shows a complete and valid file path". When would that not be the case? Doesn't find-file always have the current directory as the prompt which means it's always complete and valid?

For example if you enter some part of a file name, then the substring is not a valid file name. In this case Vertico selects the topmost file and not the prompt such that you can navigate quickly to this file. Only if the prompt is a valid path itself it is selected such that you can easily open directories. If you want to change the logic of vertico--update-candidates you can use an advice. See

vertico/vertico.el

Lines 440 to 453 in 1bd5438

;; If the current index is nil, compute new index. Select the prompt:
;; * If there are no candidates
;; * If the default is missing from the candidate list.
;; * For matching content, as long as the full content after the boundary is empty,
;; including content after point.
(unless vertico--index
(setq vertico--lock-candidate nil
vertico--index
(if (or vertico--default-missing
(= 0 vertico--total)
(and (= base (length content))
(test-completion content minibuffer-completion-table
minibuffer-completion-predicate)))
-1 0)))))))

@minad minad closed this as completed Feb 3, 2022
@minad
Copy link
Owner

minad commented Feb 4, 2022

In case you want to report the bug upstream:

(completion-boundaries "/sudo::~/" #'read-file-name-internal nil "") ;; (8 . 0)
(completion-boundaries "/sudo::/" #'read-file-name-internal nil "") ;; (8 . 0)

The return value is in both case (8 . 0) which is obviously incorrect.

(EDIT: I sent a mail to the aforementioned bug report, see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=53053.)

@ghost
Copy link
Author

ghost commented Feb 4, 2022

Oh the tidy behavior on my end is because I have / enter directory if the selection is a directory.

So rn I have to either change how vertico works or wait for the upstream fix? I was hoping there would be an easier general way to not auto-select candidates when nothing has been typed.

@minad
Copy link
Owner

minad commented Feb 4, 2022

I was hoping there would be an easier general way to not auto-select candidates when nothing has been typed.

You can use an advice or more complicated variants of that which overwrite the logic from vertico--update-candidates. It won't get easier than that.

(defun vertico--reset-index (&rest _)
  (setq vertico--index -1))
(advice-add #'vertico--update-candidates :after #'vertico--reset-index)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant