experimental patches to utop
Go to file
Jérémie Dimino cce03d4c83 Add an example showing how to build a custom utop with ocamlbuild 2012-10-29 11:11:46 +01:00
examples/custom-utop Add an example showing how to build a custom utop with ocamlbuild 2012-10-29 11:11:46 +01:00
man install utop-full with access to compiler libraries 2012-07-31 17:09:40 +02:00
src refactoring of expression rewriting 2012-10-15 11:45:44 +02:00
syntax next gen utop 2012-02-11 10:21:07 +01:00
utils fix the install-compiler-libs.sh script on Windows 2011-09-20 01:50:11 +02:00
.gitignore move to git 2012-10-17 11:32:11 +02:00
CHANGES.md move to git 2012-10-17 11:32:11 +02:00
LICENSE fix LICENSE date 2011-08-25 10:22:13 +02:00
Makefile Add a Makefile 2012-10-17 11:36:33 +02:00
README.md Add an example showing how to build a custom utop with ocamlbuild 2012-10-29 11:11:46 +01:00
_oasis Add a Makefile 2012-10-17 11:36:33 +02:00
_tags Basic functionality is almost there, however still plenty to make it production quality. In this changeset I regenerated setup.ml via. oasis 3 so it contains a huge diff. 2012-03-21 04:15:30 +01:00
configure Add a Makefile 2012-10-17 11:36:33 +02:00
dist move to git 2012-10-17 11:32:11 +02:00
myocamlbuild.ml install utop-full with access to compiler libraries 2012-07-31 17:09:40 +02:00
setup.ml Add a Makefile 2012-10-17 11:36:33 +02:00
style.css build ocamldoc documentation 2011-08-04 14:54:57 +02:00
utoprc-dark remove unused gtk resources 2012-02-26 19:28:02 +01:00
utoprc-light remove unused gtk resources 2012-02-26 19:28:02 +01:00

README.md

utop - a universal toplevel for OCaml

utop is an improved toplevel for OCaml. It can run in a terminal or in Emacs. It supports line edition, history, real-time and context sensitive completion, colors, and more.

It integrates with the tuareg and typerex modes in Emacs.

Dependencies

For building the development version, you also need to install oasis (>= 0.3.0).

utop also requires OCaml compiler libraries. Since OCaml 4.00 they are already installed, for previous versions:

  • if you are using debian, they are available as the package ocaml-compiler-libs,
  • if you are using godi, they are installed by default,
  • if you installed ocaml by hand, you can run the script utils/install-compiler-libs.sh.

Installation

To build and install utop:

$ ./configure
$ make
$ make install

Documentation and manual pages (optional)

To build the documentation:

$ make doc

It will then be installed by make install.

Tests (optionnal)

To build and execute tests:

$ ./configure --enable-tests
$ make test

Usage

To use utop, simply run:

$ utop

utop display a bar after the prompt which is used to show possible completions in real-time. You can navigate in it using Alt+Left and Alt+Right, and select one completion using Alt+Tab.

Customization

To add colors to utop, copy one of the files utoprc-dark or utoprc-light to ~/.utoprc. utoprc-dark is for terminals with dark colors (such as white on black) and utoprc-light is for terminals with light colors (such as black on white).

You can also customize the prompt of utop by setting the reference UTop.prompt.

Integration with emacs

To use utop in emacs, add the following line to your ~/.emacs file:

(autoload 'utop "utop" "Toplevel for OCaml" t)

Then you can run utop by executing the command utop in emacs.

Integration with the tuareg/typerex mode

You can replace the default toplevel used by the tuareg or typerex mode by utop, for that add the following lines to your ~/.emacs file:

(autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
(add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)

You can also complete text in a tuareg or typerex buffer using the environment of the toplevel. For that bind the function utop-edit-complete to the key you want.

Creating a custom utop-enabled toplevel

If you want to create a custom toplevel with utop instead of the classic one you need to link it with utop and its dependencies and call UTop_main.main in the last linked unit. You also need to pass the -thread switch when linking the toplevel.

The easiest way to do that is by using ocamlfind:

$ ocamlfind ocamlmktop -o myutop -thread -linkpkg -package utop myutop_main.cmo

Where myutop_main.ml contains:

let () = UTop_main.main ()

You can also use the ocamlc sub-command instead of ocamlmktop, in this case you need to pass these thee extra arguments:

  • -linkall to be sure all units are linked into the produced toplevel
  • -package compiler-libs.toplevel
  • -predicates create_toploop

With the last option ocamlfind will generate a small ocaml unit, linked just before myutop_main.cmo, which will register at startup packages already linked in the toplevel so they are not loaded again by the #require directive. It does the same with the ocamlmktop sub-command.

For example:

$ camlfind ocamlc -o myutop -thread -linkpkg -linkall -predicates create_toploop \
    -package compiler-libs.toplevel,utop myutop.cmo

Note that if you are not using ocamlfind, you will need to do that yourself. You have to call Topfind.don't_load with the list of all packages linked with the toplevel.

A full example using ocamlbuild is provided in the examples/custom-utop directory.