Function: tramp-completion-dissect-file-name

tramp-completion-dissect-file-name is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-completion-dissect-file-name NAME)

Documentation

Return a list of tramp-file-name structures for NAME.

They are collected by tramp-completion-dissect-file-name1.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
;; I misuse a little bit the `tramp-file-name' structure in order to
;; handle completion possibilities for partial methods / user names /
;; host names.  Return value is a list of `tramp-file-name' structures
;; according to possible completions.  If "localname" is non-nil it
;; means there shouldn't be a completion anymore.

;; Expected results:

;; "/x" "/[x"
;; ["x" nil nil nil]

;; "/x:" "/[x/"         "/x:y" "/[x/y"       "/x:y:" "/[x/y]"
;; ["x" nil "" nil]     ["x" nil "y" nil]    ["x" nil "y" ""]
;; ["x" "" nil nil]     ["x" "y" nil nil]

;; "/x:y@""/[x/y@"      "/x:y@z" "/[x/y@z"   "/x:y@z:" "/[x/y@z]"
;;["x" "y" nil nil]     ["x" "y" "z" nil]    ["x" "y" "z" ""]
(defun tramp-completion-dissect-file-name (name)
  "Return a list of `tramp-file-name' structures for NAME.
They are collected by `tramp-completion-dissect-file-name1'."
  (let* ((x-nil "\\|\\(\\)")
	 (tramp-completion-ipv6-regexp
	  (format
	   "[^%s]*"
	   (if (zerop (length tramp-postfix-ipv6-format))
	       tramp-postfix-host-format
	     tramp-postfix-ipv6-format)))
	 ;; "/method" "/[method"
	 (tramp-completion-file-name-structure1
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp x-nil "\\)$")
	   1 nil nil nil))
	 ;; "/method:user" "/[method/user"
	 (tramp-completion-file-name-structure2
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
	    "\\(" tramp-user-regexp x-nil   "\\)$")
	   1 2 nil nil))
	 ;; "/method:host" "/[method/host"
	 (tramp-completion-file-name-structure3
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
	    "\\(" tramp-host-regexp x-nil   "\\)$")
	   1 nil 2 nil))
	 ;; "/method:[ipv6" "/[method/ipv6"
	 (tramp-completion-file-name-structure4
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
	    tramp-prefix-ipv6-regexp
	    "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
	   1 nil 2 nil))
	 ;; "/method:user@host" "/[method/user@host"
	 (tramp-completion-file-name-structure5
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
	    "\\(" tramp-user-regexp "\\)"   tramp-postfix-user-regexp
	    "\\(" tramp-host-regexp x-nil   "\\)$")
	   1 2 3 nil))
	 ;; "/method:user@[ipv6" "/[method/user@ipv6"
	 (tramp-completion-file-name-structure6
	  (list
	   (concat
	    tramp-prefix-regexp
	    "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
	    "\\(" tramp-user-regexp "\\)"   tramp-postfix-user-regexp
	    tramp-prefix-ipv6-regexp
	    "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
	   1 2 3 nil)))
    (delq
     nil
     (mapcar
      (lambda (structure) (tramp-completion-dissect-file-name1 structure name))
      (list
       tramp-completion-file-name-structure1
       tramp-completion-file-name-structure2
       tramp-completion-file-name-structure3
       tramp-completion-file-name-structure4
       tramp-completion-file-name-structure5
       tramp-completion-file-name-structure6)))))