Portable Emacs-onna-Stick – USB Geekiness


I had quite a phase of using Emacs a while ago. One problem I hit was that I’d find a great trick for using it for PHP and JavaScript stuff at work, then forget to copy the stuff to home. Then, I found a nice code-folding trick at home, and forgot to copy that to work. Once I realised, I had to fiddle about working out what bits I needed to copy between the two installations to make everything work the same.

I’m back with Emacs now, and trying to use PlannerMode for basic ‘GTD stuff’. If I can’t take my lists to work with me, though, it’s a bit less convenient. It’s much easier to have access to the lists there than to have to email stuff to work that I need to do there, or to home that I need to do there.

Today, though, I found what seems like the answer. I already tend to carry a USB stick drive thing around with me. Now, I can run Emacs from there, with all its data stored on a ‘home’ folder on there too. I got the idea of how to do it from this blog post from clmemo@aka. It relates to doing the same thing with a version of Emacs set up for AUCTeX, but it works just the same with standard GNU Emacs.

What you need to do is…

  • Copy an emacs folder to the USB stick, just as if you were installing it – just an unzipping of the Gnu Emacs for Windows distribution (sorry – no idea if any of this works with XEmacs).
  • Under the emacs folder, there should already be a site-lisp folder. In it, create a file called site-start.el, which will be run every time Emacs starts, before your .emacs.
  • Add this code to site-start.el

(defvar usb-drive-letter (substring data-directory 0 3))
(defvar usb-home-dir (concat usb-drive-letter "home/"))

(setenv "HOME" usb-home-dir)

  • Create yourself a home folder in the root of the USB drive. Copy all your usual Emacs home stuff to there – your elisp folders, your .emacs, Plans folder if you’re using PlannerMode, etc.

If all this works as it should, when you run runemacs from the USB drive, you should find that the home path (~) is remapped to the USB drive within Emacs. For me, ~ in emacs is now ‘F:\home\’. All my Plans files, my .emacs, and all my elisp stuff can go to work and back in my pocket.

This solves a bit of a problem for me, and I’m sure I can’t be the only one with that problem – thank to clmemo@aka for showing me the answer.

Other Stuff

This isn’t my usual sort of post – I mainly post sets of photos from shoots with models, events and other things. If that sort of thing interests you, have a look at some of these recent posts while you’re here.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: