unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* find-file, file-name-handler-alist, and FTP URLs
@ 2006-05-12 15:36 Sam Steingold
  2006-05-12 22:18 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Sam Steingold @ 2006-05-12 15:36 UTC (permalink / raw)


Emacs does not handle FTP URLs correctly:
(find-file "ftp://ftp.gnu.org/pub/")
results in
Use M-x make-directory RET RET to create the directory and its parents
#<buffer ~/Mail/ftp:/ftp.gnu.org/pub/>

the expected behavior is obviously equivalent to
(find-file "/ftp.gnu.org:/pub/")

here is what I use:

(defun sds-url-to-ange-format (str)
  "Translate from the URL format to ange-ftp/efs format.
`\\(ftp\\|file\\)://user:pwd@host:port/path' ==> `/user@host#port:/path'.
Only `host' is required. If STR doesn't look like a URL, return STR."
  (let ((hre "[-a-zA-Z.0-9]+"))
    (if (string-match
         (concat "^\\(ftp://\\|file://\\)\\(" hre "\\(:" hre
                 "\\)?@\\)?\\(" hre "\\)\\(:[0-9]+\\)?\\(/[^/]*\\)?") str)
        (concat "/"
                (if (match-beginning 2)
                    (concat (substring str (match-beginning 2)
                                       (or (match-beginning 3)
                                           (- (match-end 2) 1)))
                            "@"))
                (match-string 4 str)
                (if (match-beginning 5)
                    (concat "#" (substring str (1+ (match-beginning 5))
                                           (match-end 5))))
                ":" (if (match-beginning 6)
                        (substring str (match-beginning 6))))
        str)))

(defun sds-find-file-url-handler (function filename &rest ignore)
  (funcall function (sds-url-to-ange-format filename)))

(push
 '("\\`\\(ftp://\\|file://\\)" . find-file-url-handler)
 sds-file-name-handler-alist)


any objections to adding something like that (without the sds prefix, of
course)?

-- 
Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux)
http://palestinefacts.org http://ffii.org http://honestreporting.com
http://jihadwatch.org http://truepeace.org http://camera.org
Single tasking: Just Say No.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: find-file, file-name-handler-alist, and FTP URLs
  2006-05-12 15:36 find-file, file-name-handler-alist, and FTP URLs Sam Steingold
@ 2006-05-12 22:18 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2006-05-12 22:18 UTC (permalink / raw)


> Emacs does not handle FTP URLs correctly:
> (find-file "ftp://ftp.gnu.org/pub/")
> results in
> Use M-x make-directory RET RET to create the directory and its parents
> #<buffer ~/Mail/ftp:/ftp.gnu.org/pub/>

Try url-handler-mode,


        Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-12 22:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-12 15:36 find-file, file-name-handler-alist, and FTP URLs Sam Steingold
2006-05-12 22:18 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).