Function: with-parsed-tramp-file-name

with-parsed-tramp-file-name is a macro defined in tramp.el.gz.

Signature

(with-parsed-tramp-file-name FILENAME VAR &rest BODY)

Documentation

Parse a Tramp filename and make components available in the body.

First arg FILENAME is evaluated and dissected into its components. Second arg VAR is a symbol. It is used as a variable name to hold the filename structure. It is also used as a prefix for the variables holding the components. For example, if VAR is the symbol foo, then foo will be bound to the whole structure, foo-method will be bound to the method component, and so on for foo-user, foo-domain, foo-host, foo-port, foo-localname, foo-hop.

Remaining args are Lisp expressions to be evaluated (inside an implicit progn).

If VAR is nil, then we bind v to the structure and method, user, domain, host, port, localname, hop to the components.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defmacro with-parsed-tramp-file-name (filename var &rest body)
  "Parse a Tramp filename and make components available in the body.

First arg FILENAME is evaluated and dissected into its components.
Second arg VAR is a symbol.  It is used as a variable name to hold
the filename structure.  It is also used as a prefix for the variables
holding the components.  For example, if VAR is the symbol `foo', then
`foo' will be bound to the whole structure, `foo-method' will be bound to
the method component, and so on for `foo-user', `foo-domain', `foo-host',
`foo-port', `foo-localname', `foo-hop'.

Remaining args are Lisp expressions to be evaluated (inside an implicit
`progn').

If VAR is nil, then we bind `v' to the structure and `method', `user',
`domain', `host', `port', `localname', `hop' to the components."
  (declare (indent 2) (debug (form symbolp &rest body)))
  (let ((bindings
         (mapcar
	  (lambda (elem)
            `(,(if var (intern (format "%s-%s" var elem)) elem)
              (,(intern (format "tramp-file-name-%s" elem))
               ,(or var 'v))))
	  (cdr (mapcar #'car (cl-struct-slot-info 'tramp-file-name))))))
    `(let* ((,(or var 'v) (tramp-dissect-file-name ,filename))
            ,@bindings)
       ;; We don't know which of those vars will be used, so we bind them all,
       ;; and then add here a dummy use of all those variables, so we don't get
       ;; flooded by warnings about those vars `body' didn't use.
       (ignore ,@(mapcar #'car bindings))
       ,@body)))