Compile from OCaml Replica

I use emacs with tuareg mode and I always have ocaml repl open in emacs. I was wondering if there is a way to compile the basic OCaml test files from repl, so I don't need to run compilation as a system command.

+4
source share
2 answers

As far as I know, no, but you can easily start compiling from emacs.

If you use the Mx compile command ( Cc Cc using tuareg mode ), the compilation is done in emacs compilation mode, which is nice to work with. In particular, it allows you to jump directly to erroneous positions in the code in case of a compilation error ( Mx goto-next-error or "Cx`").

With the compilation command, you select the command (shell) to start compilation. You can directly call the ocamlc -c foo.ml compiler (usually ocamlc -c foo.ml ) or use ocamlfind to facilitate compilation using external libraries and even make or ocamlbuild to automate most compilations for you. As a rule, if you have a small project using different source files, with the main.ml file, ocamlbuild main.byte will perform the task of creating an executable file from it.

Edit: Of course, you could call the system command from the top level using the Sys.command function. But I do not see the point.

+1
source

By "repl" you mean the "read-eval-print cycle" that you may have received, for example, by running run-caml in Emacs.

There is an Emacs command, compile , for compiling no matter what you do, or the files you are editing. It is usually associated with Cc Cc, but does not seem to be in my version of inf-caml. However, you can bind it to any convenient sequence (maybe not Cc Cc, which is used to interrupt OCaml toplevel).

You can change the command launched with compile (the default is make -k ). Your command line should be saved in an Emacs session. If you do not like that it is lost from session to session, write a Makefile so that the default command is correct. This is the easiest way.

+1
source

All Articles