I am using emacs with tuareg mode and I always have the ocaml repl opened inside emacs. I was wondering if there's a way of compiling basic OCaml test files from within the repl so I don't have to run the compilation as a system command.
To my knowledge there isn't, but you can easily run compilation from within emacs.
If you use the M-x compile
command (C-c C-c
using the tuareg mode), the compilation is run in emacs "compile mode" which is rather nice to work with. In particular, it allows you to jump directly at the erroneous positions in the code in case of compilation error (M-x goto-next-error
or "C-x `").
With the compile command, you choose the (shell) command to run the compilation. You can invoke the ocaml compiler directly (typically, ocamlc -c foo.ml
), or use ocamlfind
to facilitate compilation using external libraries, and even make
or ocamlbuild
to automate most of the compilation for you. Typically, if you have a small project using different source files, with a main.ml
file, ocamlbuild main.byte
will do the job of building an executable from it.
Edit : of course, you could call a system command from within the toplevel, using the Sys.command
function. But I don't see the point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With