May 12, 2006

Portable Emacs

Posted in Emacs at 13:07 by theBlackDragon

While reading I came accross this post where somebody asked how he could make a portable app out of Emacs' Windows version.

So since I'm still at my internship (where they use Windows) and just recently obtained an iAudio X5L portable media player which behaves like an USB2 harddisk to the OS I wondered if I could manage to make Emacs portable.

Short version: I could, the "hardest" part was in fact not even Emacs related, but my sheer lack of knowledge about Windows batch script.

I started by creating a "SOFT" folder on my external drive (named E: by Windows on this box) and extracted the altest Emacs build from the ntemacs project in this directory, thus creating "E:\SOFT\emacs" with all the usual subfolders.

Next I created a site-lisp/site-start.el file and added the following as suggested on usenet:

(let ((home (concat (substring (car command-line-args) 0 2) "/SOFT")))
  (setq user-init-file (concat home "/config/.emacs"))
  (setq auto-save-list-file-prefix (concat home "/config/.emacs.d/auto-save-list/.saves-")))

You'll need to adapt this to your particular environment of course.

This makes Emacs load my user-init-file (aka ".emacs") from "E:/SOFT/config/.emacs" and moves the auto-save-list to the external device as well, this should be superfluous though as I change the location of HOME as described later, but it accounts for the cases that you don't want to change your HOME.

This is in fact the entire Emacs side of the story, though you will probably have some work making your elisp packages work with relative paths if you didn't take that into account before.

Now you need to redefine HOME in Windows (well, you don't need to but I find it useful), you can either do that globally with the System Properties or autoexec.bat in DOS based Windows versions, but I preferred to make it dynamic by writing a wrapper batfile that sets this variable and then launches Emacs. I named it runemacs.bat (how appropriate;)) and put it in Emacs' bin directory, the content looks like this:

set HOME=%CD%\..\..\config

That's it! You can now run Emacs entirely from your external drive!


  1. […] will run entirely from a USB flash drive. Most importantly, I even found instructions (and also here) to run the Windows version of GNU Emacs from a flash drive. Granted, I always preferred the CLI […]

  2. […] Portable Emacs « theBlackDragon’s Blog (tags: emacs portable windows) […]

Leave a Reply

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

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

Google photo

You are commenting using your Google 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