crshd Introducing Emacs Fetch

Thursday, November 28, 2013 – Emacs

Let's say you like to use fancy JS frameworks, like jQuery. A lot. Now, what do you do? You could go and download a fresh copy every time you need to use it, but that's so tedious. Or, you could save a copy somewhere in a convenient location on your harddrive, and get it from there. But then you'd still have to go and grab the latest every time, or settle for using an older, out-of-date version.

The Solution

Somebody thought to himself: “What if there was a plugin that would automatically pull in the latest copy of a file, simply by typing a keyboard shortcut. It’ll perform a curl request to your specified URL (saved away for future use), and allow you to rest assured that, for all new projects, you’re using the latest copy of a particular asset.

And then they made one.

The Second Dilemma, and Another Solution

This person was Weslly Honorato, and he made a great plugin. Except it has one major flaw: It's for the wrong editor. The plugin I'm talking about is Nettuts+ Fetch, and it is for Sublime Text. It's a great plugin for a nice editor, but I prefer Emacs. So what do I do? I bend the powers of Emacs to work in my favor, and write a plugin of my own.

Installation Instructions

This one is easy. Grab the latest source from github, and package-install-file that stuff.

$ git clone
$ emacs --eval '(package-install-file "fetch.el/fetch.el")'

I have submitted a request to get this package included in MELPA, so keep an eye on that to make the installation process even simpler.

Edit: It has since been included into the repo, so go ahead and get it from there.


This is where it gets a bit more complicated (but not much, I swear!). First of all, you have to add your favorite package to the association list (actually, this step is optional, more on that later). To do so, drop something like this in your .emacs:

(add-to-list 'fetch-package-alist
             '("jquery" . "") t)

Now, grabbing the latest release of jQuery is just an M-x fetch-resource away. fetch-resource will supply you with a list of packages you defined, for you to pick from.

Alternatively, you don't even need to modify any alist, or touch your .emacs. You can call the function M-x fetch-url, and you get a chance to input the URL directly. This allows you to download and use any package quickly, without worrying about leaving the comfort of your editor. And you don't even need to put on pants!

But Wait, There's More!

Apart from just handling single files, you can grab entire archives! Take Bootstrap for example. You can add the download link to the alist as usual, and fetch.el will take care of everything, from downloading to unpacking the .zip.