unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Sam Steingold <sds@podval.org>
Subject: find-file, file-name-handler-alist, and FTP URLs
Date: Fri, 12 May 2006 11:36:54 -0400	[thread overview]
Message-ID: <alhd3vtfu1.fsf@quant8.janestcapital.quant> (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.

             reply	other threads:[~2006-05-12 15:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-12 15:36 Sam Steingold [this message]
2006-05-12 22:18 ` find-file, file-name-handler-alist, and FTP URLs Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alhd3vtfu1.fsf@quant8.janestcapital.quant \
    --to=sds@podval.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).