Articles

Creating a portable emacs installation, and a portable Caml or OCaml installation

Running emacs from a USB stick (Running emacs as a portable application).

Appendix: Creating a portable Caml environment.

Quick setup

Although this tutorial describes the whole process of configuring your emacs and Caml installations, you can go for the quick option, and download a package which contains all the files you need. Just unzip it, and follow the instructions in the README.txt file.


Summary

This article takes you through the required steps to configure emacs (the GNU text editor) to run from a usb stick ; that is, to create a "portable" version of emacs. It will help you configure it so that your settings are kept local to your usb device. It then focuses on how to install a Caml (Light) or Ocaml distribution to your USB device, and use it from emacs.
Difficulty: Easy. Time needed: Approx. 5 minutes.

Note: This method has not been tested under linux, although it should work perfectly.

Step 1: Downloading the necessary files

Download the latest version of Emacs from the GNU website. Unzip the contents of the file to an emacs folder on your USB device.

Step 2: Configuring emacs

Now that emacs is installed, you have to tell it where to look for configuration files. This can be done very easily by creating a site-start.el file in the site-lisp directory (located in your emacs directory). In this file, put the following lines:

These lines allow you to force emacs to think that your HOME directory (the one where emacs searches for config files) is actually the folder on your usb disk where emacs is located (\emacs). Thus, if you create a .emacs file, it should be located in \emacs\.emacs.

Finally, create a documents folder in \emacs, and a run-emacs.bat file in \emacs, containing the following lines:

This way, emacs will start in the documents directory when you double-click the run-emacs.bat file.

(Optional) Step 3: Creating a portable caml installation.

This part is intended for people who want to be able to edit and run Caml or OCaml programs from their portable insatllation.

Downloading the files

Download and install Caml Light or OCaml from the INRIA website. Once you have installed the package (you have to install it, since there is no way to get zipped precompiled binaries, and since Caml and OCaml need environment vars to be set), create a caml-bin directory in your emacs directory, and a camllight or ocaml directory in it. Then go to the folder where you installed your Caml distribution, and copy the folders called bin, lib, and doc to your caml directory on your usb drive (emacs\caml-bin\ocaml or emacs\caml-bin\camllight).

Your file tree should now look like this:

Or like this:

Now, append the following lines to your site-start.el file (\emacs\site-lisp\site-start.el), which define the environment variables needed by both ocaml and caml light to start:

Now, download the tuareg mode for emacs, which enables you to run caml from emacs. Unzip the files tuareg.el and caml-debug.el in your emacs\site-lisp directory. Here comes the tricky bit: you have to tell the tuareg mode where to look for caml binaries.

Open the file \site-lisp\tuareg.el, and find the line starting with (defvar tuareg-interactive-program "ocaml", and replace "ocaml", including the quotation marks, with camllight-exe if you want to run Caml Light, or ocaml-exe for OCaml. You're in fact setting up the tuareg mode to prompt you by default with the right path when starting caml binaries.

Finally, create a file called .emacs in \emacs, and add the following lines to it:

More information on the emacs Caml mode can be found on the INRIA's website.

You can download a zip archive containing the files mentionned in this article.

Any questions are very welcome. Ideas? Contact me at createsoftware AT users.sourceforge.net

Clément Pit--Claudel.

Article licensed under GNU GPL v3. Copies allowed, provided the author name is mentionned.