changeset 5668:ee95ef1e644c

Update `file-name-remote-p'. 2008-01-03 Michael Sperber <mike@xemacs.org> * files.el (file-remote-p): Synch with GNU Emac: Add `identification' and `connected' parameters, and use file-name handler if available. Zap support for ange-ftp.
author Mike Sperber <sperber@deinprogramm.de>
date Mon, 02 Jul 2012 20:39:12 +0200
parents b4715fcbe001
children f45338de7caa
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 46 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon May 14 15:16:47 2012 +0100
+++ b/lisp/ChangeLog	Mon Jul 02 20:39:12 2012 +0200
@@ -5208,6 +5208,12 @@
 	Bind print-gensym-alist to nil, as we do within
 	byte-compile-output-docform.
 
+2008-01-03  Michael Sperber  <mike@xemacs.org>
+
+	* files.el (file-remote-p): Synch with GNU Emac: Add
+	`identification' and `connected' parameters, and use file-name
+	handler if available.  Zap support for ange-ftp.
+
 2008-01-04  Michael Sperber  <mike@xemacs.org>
 
 	* code-files.el (insert-file-contents):
--- a/lisp/files.el	Mon May 14 15:16:47 2012 +0100
+++ b/lisp/files.el	Mon Jul 02 20:39:12 2012 +0200
@@ -4482,14 +4482,46 @@
       (error "Apparently circular symlink path"))))
 
 ;; Suggested by Michael Kifer <kifer@CS.SunySB.EDU>
-(defun file-remote-p (file-name)
-  "Test whether FILE-NAME is looked for on a remote system."
-  (cond ((not (declare-boundp allow-remote-paths)) nil)
-	((fboundp 'ange-ftp-ftp-path)
-	 (declare-fboundp (ange-ftp-ftp-path file-name)))
-	((fboundp 'efs-ftp-path)
-	 (declare-fboundp (efs-ftp-path file-name)))
-	(t nil)))
+(defun file-remote-p (file &optional identification connected)
+  "Test whether FILE specifies a location on a remote system.
+Return an identification of the system if the location is indeed
+remote.  The identification of the system may comprise a method
+to access the system and its hostname, amongst other things.
+
+For example, the filename \"/user@host:/foo\" specifies a location
+on the system \"/user@host:\".
+
+IDENTIFICATION specifies which part of the identification shall
+be returned as string.  IDENTIFICATION can be the symbol
+`method', `user' or `host'; any other value is handled like nil
+and means to return the complete identification string.
+
+If CONNECTED is non-nil, the function returns an identification only
+if FILE is located on a remote system, and a connection is established
+to that remote system.
+
+`file-remote-p' will never open a connection on its own."
+  (let ((handler (find-file-name-handler file 'file-remote-p)))
+    (cond
+     (handler
+      (funcall handler 'file-remote-p file identification connected))
+     ;; legacy code; can probably go by mid-2008
+     ((fboundp 'efs-ftp-path)
+      (let ((parsed (declare-fboundp (efs-ftp-path file))))
+	(and parsed
+	     (let ((host (nth 0 parsed))
+		   (user (nth 1 parsed)))
+	       (and (or (not connected)
+		    (let ((proc (get-process (declare-fboundp (efs-ftp-process-buffer host user)))))
+		      (and proc (processp proc)
+			   (memq (process-status proc) '(run open)))))
+		(cond
+		 ((eq identification 'method) (and parsed "ftp"))
+		 ((eq identification 'user) user)
+		 ((eq identification 'host) host)
+		 (t
+		  (concat "/" user "@" host ":/"))))))))
+     (t nil))))
 
 
 ;; We use /: as a prefix to "quote" a file name