minad / vertico

:dizzy: vertico.el - VERTical Interactive COmpletion
GNU General Public License v3.0
1.48k stars 60 forks source link

vertico-directory-tidy for tramp directories #241

Closed tpeacock19 closed 2 years ago

tpeacock19 commented 2 years ago

I've noticed that when using vertico-directory-tidy that tramp directories are not cleaned correctly. They result in two cases for me:

/sudo:root@remote:/usr/local/share/ [insert backslash twice] results in /

/sudo:root@remote:/usr/local/share/ [insert backslash "tmp"] results in: /sudo:root@remote:/usr/local/share//tmp

The first one takes the minibuffer back to the local host of which is utlimately correct and stays on the remote host but does not get the benefit of tidying. I've come up with a solution to just copy a tramp version of vertico-tramp-directory-tidy and place it in the rfn-eshadow-update-overlay-hook before vertico-directory-tidy. It needed to be before or else Case 1 from above would continue to happen.

(defun vertico-tramp-directory-tidy ()
  "Tidy shadowed file name, see `rfn-eshadow-overlay'."
  (when (and (eq this-command #'self-insert-command)
             (bound-and-true-p tramp-rfn-eshadow-overlay)
             (overlay-buffer tramp-rfn-eshadow-overlay)
             (= (point) (point-max))
             (or (>= (- (point) (overlay-end tramp-rfn-eshadow-overlay)) 2)
                 (eq ?/ (char-before (- (point) 2)))))
    (delete-region (overlay-start tramp-rfn-eshadow-overlay) (overlay-end tramp-rfn-eshadow-overlay))))

I'm not sure if this is something you'd want in Vertico since there isn't much tramp specific code. So maybe it should go in the Wiki?

minad commented 2 years ago

Thanks for the suggestion. I tried to fix this in https://github.com/minad/vertico/commit/f0347b3df5076cde205efcec0148d203df0813c4. Please check if my fix solves the issue satisfactorily. I tested this only very lightly!

tpeacock19 commented 2 years ago

Yes, this works as expected. didn't think to use dolist, much simpler.