If I have a URL to a file (for example, this gist), what's the easiest way to fetch that file from Emacs and edit a copy of it? Is there a better option than M-! curl -n [insert URL here] RET?

I'd consider an answer "better" if it didn't rely on an external facility, for instance. Also if it used the remote name of the file as the local file.

I could certainly script up a solution to this myself but it seems like a pretty normal thing to do—is there existing functionality to do this within Emacs? Is there a pre-existing package?

  • 1
    I personally like your solution, which is easy enough to incorporate into a custom function that has a prompt to type or paste the url, and then uses start-process, save the file, and open it up in a buffer -- about 5 lines of code and you have yourself a custom function, perhaps a few additional lines to choose a name -- e.g., default is the file name, or edit the name to something different in the minibuffer, choose the location to save the file, etc.
    – lawlist
    Commented Apr 13, 2015 at 22:06
  • 2
    Here is a link to a related thread entitled Download a File with Emacs Lisp: stackoverflow.com/a/4449823/2112489
    – lawlist
    Commented Apr 13, 2015 at 22:23

2 Answers 2


M-x browse-url-emacs RET URL RET

  • This is a pretty good solution. The downsides I see are: I have to exit read-only-mode if I want to edit to edit the buffer contents, and I have to use C-x C-w to save the file because otherwise it will try to save back to the remote host. Also it seems to make a remote request when I kill the buffer (not sure why, could be a local issue with a hook). All in all quite good.
    – camdez
    Commented Apr 14, 2015 at 15:01
  • For me, this just results in url-directory-files: Symbol’s function definition is void: nil. Commented Feb 16 at 7:20
  • @PhilippLudwig: In which version of Emacs? Do you get the same if you start emacs with emacs -Q?
    – phils
    Commented Feb 16 at 8:04
  • @phils Works fine with emacs -Q, so it is probably something in my configuration. Commented Feb 16 at 13:20
,----[ C-h f url-handler-mode RET ]
| url-handler-mode is an interactive autoloaded compiled Lisp function
| in `url-handlers.el'.
| (url-handler-mode &optional ARG)
| Toggle using `url' library for URL filenames (URL Handler mode).
  • 4
    Just quoting the terse docstring for url-handler-mode makes this a poor answer. Could you please expand on how your answer relates to the question and how it solves the problem?
    – user2005
    Commented Apr 14, 2015 at 10:20
  • That doc string is pretty much useless...basically what it does (AFAICT) is that it makes commands like find-file aware of http://, https://, file://, and nfs:// URLs (it does this by manipulating file-name-handler-alist). It's a pretty good solution! Downsides are: I have to jump out of ido-find-file (it seems to get confused), then clear the minibuffer, then yank, then yank-pop (to get past what I cleared...), kick it out of read-only-mode if I want to edit, use C-x C-w to write (otherwise it tries to write back to the server), and type out the file name manually.
    – camdez
    Commented Apr 14, 2015 at 14:42
  • Strangely it also makes a remote request when I kill the buffer. Not yet sure what that's about...
    – camdez
    Commented Apr 14, 2015 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.