From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Function to know weither a dir is local or remote Date: Thu, 20 Oct 2022 10:27:23 +0300 Message-ID: References: <825ygfngbw.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13968"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) Cc: help-gnu-emacs@gnu.org To: Pascal Quesseveur Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 20 09:33:57 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olQ3x-0003PF-FC for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 20 Oct 2022 09:33:57 +0200 Original-Received: from localhost ([::1]:51002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olQ3w-0006Dn-11 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 20 Oct 2022 03:33:56 -0400 Original-Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olQ0k-0003Zl-HI for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 20 Oct 2022 03:30:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olPyV-0003ZQ-LS for help-gnu-emacs@gnu.org; Thu, 20 Oct 2022 03:28:19 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:56751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olPyT-0008E4-O2 for help-gnu-emacs@gnu.org; Thu, 20 Oct 2022 03:28:19 -0400 Original-Received: from localhost ([::ffff:197.239.40.195]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000055D66.000000006350F870.00007707; Thu, 20 Oct 2022 00:27:43 -0700 Mail-Followup-To: Pascal Quesseveur , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <825ygfngbw.fsf@gmail.com> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:140175 Archived-At: * Pascal Quesseveur [2022-10-20 10:04]: > Hello, > > I wanted to know if there is a function to know weither a file path > denotes a local or a remote file. file-remote-p is a byte-compiled Lisp function in ‘files.el’. (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. The string returned for IDENTIFICATION ‘localname’ can differ depending on whether there is an existing connection. 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. 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". Other relevant functions are documented in the file group. Probably introduced at or before Emacs version 22.1. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/