The Emacs homepage has all the information on emacs.

Getting emacs

Precompiled binaries are found here. Here is a FAQ on Windows and emacs.
Macintosh OS X
OS X comes with emacs, but that version supports terminal use only and so you want a better version. A prebuilt binary of full emacs is found here.
Linux comes with emacs installed already.

Learning Emacs

If you are not familiar with emacs, control-H t is an interactive tutorial to get you going. control-H i gets you into the emacs info system; middle-click on Emacs to read the documentation about the editor. This documentation is also available on a webpage. A good emacs tutorial webpage here.

Using emacs with OCaml

You will need the caml-mode addition to emacs to effectively edit ML programs.

There are two things you need to set up in order to get caml mode working

  1. You need to install the emacs caml mode files in a place where your version of emacs can find them;
  2. You need to add a few lines to your .emacs preferences file to tell emacs to start up caml mode on ml files.

Installing Emacs caml mode

There are several ways you can get this mode installed.
  1. If you are using any CS department UNIX machine, it should already be installed.
  2. Many installs of ocaml on UNIX machines will ask you if you want to install the emacs mode somewhere during the ocaml install -- just say yes and you are all set.
  3. If you downloaded the ocaml source distribution, cd to subdirectory emacs and make install.
  4. If the three options above are not working, then we suggest you manually install your own copy of the caml mode.
    1. Pick a nice location LOC for the files. The best location is in the site-lisp/ directory of your emacs installation (e.g. /usr/local/lib/emacs/site-lisp/), but any location will work.
    2. Unzip the files here into LOC (put the .el files directly into LOC)
    3. (optional) cd LOC and run the following command:
      emacs --batch --eval '(progn (setq load-path (cons "." load-path)) (byte-compile-file "caml-xemacs.el") (byte-compile-file "caml-emacs.el") (byte-compile-file "caml.el") (byte-compile-file "inf-caml.el") (byte-compile-file "caml-help.el") (byte-compile-file "caml-types.el") (byte-compile-file "camldebug.el"))'
      -- this will create .elc files which will be a touch more efficient. No big deal if you don't do it.

Configuring Caml mode in your .emacs file

You need to include the following lines in your .emacs file (if you don't have a .emacs file, make one in your home directory with these lines in it):
; If you used option 4 above and installed your own version of the
; files and not in the site-lisp/ directory, uncomment this line and
; replace LOC below with the directory you put the files in
; (setq load-path (cons "LOC" load-path))

(setq auto-mode-alist
          (cons '("\\.ml[iylp]?$" . caml-mode) auto-mode-alist))
(autoload 'caml-mode "caml" "Major mode for editing Caml code." t)
(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t)

; for highlighting

(if window-system (require 'caml-font))
Note for Windows users: Windows doesn't always have a notion of "home" directory; in that case you can put the .emacs file at C:/. More detailed information on the .emacs file location for Windows users.

Using Caml Mode

In emacs, every file that ends in .ml will automatically load caml-mode; there will be a (caml) in the status line at the bottom indicating you are in caml mode. Also, you can execute the extended command caml-mode (type meta-x caml-mode; meta-x is either holding down the meta-key and pressing x, or ESC followed by x)) to start caml-mode in a buffer. To start a shell window running ocaml, use the extended command run-caml (or do C-c C-s which will start a caml shell if it is not already running).

The caml-mode distribution includes no documentation but is easy to use; control-h m from within emacs gets you the caml mode command list. The main useful commands (C-c means control-C, etc) are

C-c C-e		evaluate the phrase the cursor is sitting in the middle of
C-c C-r		evaluate the whole selected region
C-c C-s		show the shell window; will automatically run-caml if not running
C-c `		go to exact error location in the source

Last modified: Wed Feb 15 10:24:59 EST 2006