+ (cond ((and ivy--directory
+ (or
+ (and
+ (not (string= ivy--current "./"))
+ (cl-plusp ivy--length)
+ (file-directory-p
+ (setq dir (expand-file-name
+ ivy--current ivy--directory))))))
+ (ivy--cd dir)
+ (ivy--exhibit))
+ ((string-match "\\`/\\([^/]+?\\):\\(?:\\(.*\\)@\\)?" ivy-text)
+ (let ((method (match-string 1 ivy-text))
+ (user (match-string 2 ivy-text))
+ 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 (cl-delete-duplicates res :test #'equal))
+ (let ((host (ivy-read "Find File: "
+ (mapcar #'ivy-build-tramp-name res))))
+ (when host
+ (setq ivy--directory "/")
+ (ivy--cd (concat "/" method ":" host ":"))))))
+ (t
+ (ivy-done))))))
+
+(defcustom ivy-tab-space nil
+ "When non-nil, `ivy-partial-or-done' should insert a space."
+ :type 'boolean)
+
+(defun ivy-partial-or-done ()
+ "Complete the minibuffer text as much as possible.
+If the text hasn't changed as a result, forward to `ivy-alt-done'."
+ (interactive)
+ (if (and (eq (ivy-state-collection ivy-last) #'read-file-name-internal)
+ (string-match "\\`/" ivy-text))
+ (let ((default-directory ivy--directory))
+ (minibuffer-complete)
+ (setq ivy-text (ivy--input))
+ (when (and (file-directory-p ivy-text)
+ (= ivy--length 1))
+ (ivy--cd (expand-file-name ivy-text))))
+ (or (ivy-partial)
+ (when (or (eq this-command last-command)
+ (eq ivy--length 1))
+ (ivy-alt-done)))))
+
+(defun ivy-partial ()
+ "Complete the minibuffer text as much as possible."
+ (interactive)
+ (let* ((parts (or (split-string ivy-text " " t) (list "")))
+ (postfix (car (last parts)))
+ (completion-ignore-case t)
+ (new (try-completion postfix
+ (mapcar (lambda (str) (substring str (string-match postfix str)))
+ ivy--old-cands))))
+ (cond ((eq new t) nil)
+ ((string= new ivy-text) nil)
+ (new
+ (delete-region (minibuffer-prompt-end) (point-max))
+ (setcar (last parts) new)
+ (insert (mapconcat #'identity parts " ")
+ (if ivy-tab-space " " ""))
+ t))))