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."
  (tramp-skeleton-file-name-all-completions filename directory
    (let ((fullname
	   (tramp-drop-volume-letter (expand-file-name filename directory)))
	  (directory (tramp-drop-volume-letter directory))
	  tramp--last-hop-directory hop result result1)

      ;; Suppress hop from completion.
      (when (string-match
	     (rx
	      (regexp tramp-prefix-regexp)
	      (group (+ (regexp tramp-remote-file-name-spec-regexp)
			(regexp tramp-postfix-hop-regexp))))
	     fullname)
	(setq hop (match-string 1 fullname)
	      fullname (replace-match "" nil nil fullname 1)
	      tramp--last-hop-directory
	      (tramp-make-tramp-file-name (tramp-dissect-hop-name hop))))

      (let (;; When `tramp-syntax' is `simplified', we need a default method.
	    (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)

	;; 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)))
				   all-user-hosts))))

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

	;; Add hop.
	(dolist (elt result)
          (when elt
	    (setq elt (replace-regexp-in-string
		       tramp-prefix-regexp (concat tramp-prefix-format hop) elt))
	    (push (substring elt (length directory)) result1)))

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