Subject: 24.3; ffap-url-unwrap-remote fails for remote file URIs

From: Jens Lechtenboerger <[email-masked]>
Date: Thu, 14 Mar 2013 18:24:23 +0100

Hi there,

I’d like to access remote file URIs via ffap and ssh, e.g., /bar on
host foo via “file://foo/bar”.  However, the behavior of
ffap-url-unwrap-remote has changed from Emacs 23 to 24.

I’m using:

src/emacs -Q
(ffap-bindings)
(setq ffap-ftp-default-user nil)

In Emacs 23.4, with point in “file://foo/bar”, “C-x C-f” shows
“/foo:/bar” in  
the minibuffer, and RET retrieves the file via ssh, which is good.

In Emacs 24.3, “C-x C-f” shows “file://foo/bar”, and RET opens a
browser, which tries to access “file:///bar”, which is incorrect as
it misses the host.

The file scheme is not recognized as remote one.  Thus:
(setq ffap-url-unwrap-remote '("ftp" "file"))
Now, “C-x C-f” shows “/file:foo:/bar”, and RET leads to the error:
“Host `foo' looks like a remote host, `file' can only use the local host”

I’m not sure whether the previous result should be changed
somewhere.  Why should file only use the local host?

However, the problem can be avoided by the following version of
ffap-url-unwrap-remote.  Moreover, changing ffap-ftp-default-user is
not necessary any more.

(defun ffap-url-unwrap-remote (url)
  "Return URL as a remote file name, or nil."
  (let* ((obj    (url-generic-parse-url url))
	 (scheme (url-type obj))
	 (valid-schemes (if (listp ffap-url-unwrap-remote)
			    ffap-url-unwrap-remote
			  '("ftp")))
	 (host (url-host obj))
	 (port (url-port-if-non-default obj))
	 (user (url-user obj))
	 (filename (car (url-path-and-query obj))))
    (when (and (member scheme valid-schemes)
	       (string-match "\\`[a-zA-Z][-a-zA-Z0-9+.]*\\'" scheme)
	       (not (equal host "")))
      (concat "/"
	      (if (not (string= scheme "file"))
		  (concat scheme ":"))
	      (if user (concat user "@"))
	      host
	      (if port (concat "#" (number-to-string port)))
	      ":" filename))))

Best wishes
Jens