Function: file-remote-p
file-remote-p is a byte-compiled function defined in files.el.gz.
Signature
(file-remote-p FILE &optional IDENTIFICATION CONNECTED)
Documentation
Test whether FILE specifies a location on a remote system.
A file is considered remote if accessing it is likely to be slower or less reliable than accessing local files.
file-remote-p never opens a new remote connection. It can
reuse only a connection that is already open.
Return nil or a string identifying the remote connection
(ideally a prefix of FILE). Return nil if FILE is a relative
file name.
When IDENTIFICATION is nil, the returned string is a complete remote identifier: with components method, user, and host. The components are those present in FILE, with defaults filled in for any that are missing.
IDENTIFICATION can specify which part of the identification to
return. IDENTIFICATION can be the symbol method, user,
host, or localname. Any other value is handled like nil and
means to return the complete identification.
If the remote FILE does not contain a method, a user name, or a host
name, the respective default value is returned. The string returned for
IDENTIFICATION localname can differ depending on whether there is an
existing connection. File name handler specific implementations could
support further IDENTIFICATION symbols; Tramp, for example, knows also
the hop symbol.
If CONNECTED is non-nil, return an identification only if FILE is
located on a remote system and a connection is established to
that remote system. If CONNECTED is never, never use an
existing connection to return the identification (this is
otherwise like a value of nil).
Tip: You can use this expansion of remote identifier components
to derive a new remote file name from an existing one. For
example, if FILE is "/sudo::/path/to/file" then
(concat (file-remote-p FILE) "/bin/sh")
returns a remote file name for file "/bin/sh" that has the
same remote identifier as FILE but expanded; a name such as
"/sudo:root@myhost:/bin/sh".
Probably introduced at or before Emacs version 22.1.
Aliases
org-file-remote-p (obsolete since 9.2)
ediff-file-remote-p (obsolete since 29.1)
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-remote-p (file &optional identification connected)
"Test whether FILE specifies a location on a remote system.
A file is considered remote if accessing it is likely to
be slower or less reliable than accessing local files.
`file-remote-p' never opens a new remote connection. It can
reuse only a connection that is already open.
Return nil or a string identifying the remote connection
\(ideally a prefix of FILE). Return nil if FILE is a relative
file name.
When IDENTIFICATION is nil, the returned string is a complete
remote identifier: with components method, user, and host. The
components are those present in FILE, with defaults filled in for
any that are missing.
IDENTIFICATION can specify which part of the identification to
return. IDENTIFICATION can be the symbol `method', `user',
`host', or `localname'. Any other value is handled like nil and
means to return the complete identification.
If the remote FILE does not contain a method, a user name, or a host
name, the respective default value is returned. The string returned for
IDENTIFICATION `localname' can differ depending on whether there is an
existing connection. File name handler specific implementations could
support further IDENTIFICATION symbols; Tramp, for example, knows also
the `hop' symbol.
If CONNECTED is non-nil, return an identification only if FILE is
located on a remote system and a connection is established to
that remote system. If CONNECTED is `never', never use an
existing connection to return the identification (this is
otherwise like a value of nil).
Tip: You can use this expansion of remote identifier components
to derive a new remote file name from an existing one. For
example, if FILE is \"/sudo::/path/to/file\" then
(concat (file-remote-p FILE) \"/bin/sh\")
returns a remote file name for file \"/bin/sh\" that has the
same remote identifier as FILE but expanded; a name such as
\"/sudo:root@myhost:/bin/sh\"."
(when-let* ((handler (find-file-name-handler file 'file-remote-p)))
(funcall handler 'file-remote-p file identification connected)))