Reputation: 228
If I start a custom toplevel in Emacs/tuareg with the tuareg-run-caml
function, I need to give the path to the toplevel and the various -I
options it requires to find the CMI files. This typing is tedious, is there a more convenient way to start a custom toplevel?
Upvotes: 4
Views: 581
Reputation: 9377
One approach is to add a .ocamlinit
in the project directory that uses #directory
to add whatever paths are necessary to the toplevel. You can also use this to install printers, add shorter names for commonly used modules, run test code, etc.
Note that you probably want that project specific .ocamlinit
to execute ~/.ocamlinit
, since things like opam tend to put bits and pieces in there. It might look something like this:
#use "/home/foo/.ocamlinit"
#directory "_build"
open Printf
module V = VeryLongModuleName
Note that #use
expects a hard-coded path. This unfortunately interferes with distributing the file.
I further automate this by having an emacs command to start a toplevel that searches the current directory for a file called *.top
to execute, falling back to ocaml
if none is found. As ocamlbuild
provides a fairly simple method of building these files, this avoids much of the tedium of getting a project loaded into a useable toplevel.
Upvotes: 1