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

Tramp completion returns irrelevant entries #3013

Open
ywwry66 opened this issue Mar 3, 2023 · 0 comments
Open

Tramp completion returns irrelevant entries #3013

ywwry66 opened this issue Mar 3, 2023 · 0 comments

Comments

@ywwry66
Copy link
Contributor

ywwry66 commented Mar 3, 2023

With ivy mode on, typing in /ssh: in dired mode followed by C-j will return irrelevant completion entries. For example, it returns the local hostname; it also returns a nil entry.

After looking at tramp.el, I figured the following possible fix. In the function tramp-completion-handle-file-name-all-completions which tramp.el uses to handle completion, variables tramp-default-user tramp-default-user-alist tramp-default-host tramp-default-host-alist are set to nil within the function so that tramp-get-completion-function won't output things like local hostname. As for the nil entry, it can be removed manually.

(defun ivy--tramp-candidates ()
   (let ((method (match-string 1 ivy-text))
         (user (match-string 2 ivy-text))
         (rest (match-string 3 ivy-text))
+	 (tramp-default-method
+	  (and (string-empty-p tramp-postfix-method-format)
+	       tramp-default-method))
+	 (tramp-default-method-alist
+	  (and (string-empty-p tramp-postfix-method-format)
+	       tramp-default-method-alist))
+	 tramp-default-user tramp-default-user-alist
+	 tramp-default-host tramp-default-host-alist
         res)
     (dolist (x (tramp-get-completion-function method))
       (setq res (append res (funcall (car x) (cadr x)))))
     (setq res (delq nil res))
     (when user
       (dolist (x res)
         (setcar x user)))
     (setq res (delete-dups res))
+    (setq res (delete '(nil nil) res))
     (let* ((old-ivy-last ivy-last)
            (enable-recursive-minibuffers t)
            (host (let ((ivy-auto-select-single-candidate nil))
                   (ivy-read "user@host: "
                             (mapcar #'ivy-build-tramp-name res)
                             :initial-input rest))))
      (setq ivy-last old-ivy-last)
      (when host
        (setq ivy--directory "/")
        (ivy--cd (concat "/" method ":" host ":/"))))))
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