Function: tramp-completion-handle-file-name-all-completions

tramp-completion-handle-file-name-all-completions is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-completion-handle-file-name-all-completions FILENAME DIRECTORY)

Documentation

Like file-name-all-completions for partial Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
;; Method, host name and user name completion.
;; `tramp-completion-dissect-file-name' returns a list of
;; `tramp-file-name' structures.  For all of them we return possible
;; completions.
(defun tramp-completion-handle-file-name-all-completions (filename directory)
  "Like `file-name-all-completions' for partial Tramp files."
  (let ((fullname
	 (tramp-drop-volume-letter (expand-file-name filename directory)))
	;; When `tramp-syntax' is `simplified', we need a default method.
	(tramp-default-method
	 (and (zerop (length tramp-postfix-method-format))
	      tramp-default-method))
	(tramp-default-method-alist
	 (and (zerop (length tramp-postfix-method-format))
	      tramp-default-method-alist))
	tramp-default-user tramp-default-user-alist
	tramp-default-host tramp-default-host-alist
	hop result result1)

    ;; Suppress hop from completion.
    (when (string-match
	   (concat
	    tramp-prefix-regexp
	    "\\(" "\\(" tramp-remote-file-name-spec-regexp
                        tramp-postfix-hop-regexp
	    "\\)+" "\\)")
	   fullname)
      (setq hop (match-string 1 fullname)
	    fullname (replace-match "" nil nil fullname 1)))

    ;; Possible completion structures.
    (dolist (elt (tramp-completion-dissect-file-name fullname))
      (let* ((method (tramp-file-name-method elt))
	     (user (tramp-file-name-user elt))
	     (host (tramp-file-name-host elt))
	     (localname (tramp-file-name-localname elt))
	     (m (tramp-find-method method user host))
	     all-user-hosts)

	(unless localname        ;; Nothing to complete.

	  (if (or user host)

	      ;; Method dependent user / host combinations.
	      (progn
		(mapc
		 (lambda (x)
		   (setq all-user-hosts
			 (append all-user-hosts
				 (funcall (nth 0 x) (nth 1 x)))))
		 (tramp-get-completion-function m))

		(setq result
		      (append result
			      (mapcar
			       (lambda (x)
				 (tramp-get-completion-user-host
				  method user host (nth 0 x) (nth 1 x)))
			       (delq nil all-user-hosts)))))

	    ;; Possible methods.
	    (setq result
		  (append result (tramp-get-completion-methods m)))))))

    ;; Unify list, add hop, remove nil elements.
    (dolist (elt result)
      (when elt
	(string-match tramp-prefix-regexp elt)
	(setq elt (replace-match (concat tramp-prefix-format hop) nil nil elt))
	(push
	 (substring elt (length (tramp-drop-volume-letter directory)))
	 result1)))

    ;; Complete local parts.
    (append
     result1
     (ignore-errors
       (tramp-run-real-handler
	#'file-name-all-completions (list filename directory))))))