Dear all,
I’m more and more interested in finding ways to address this use case:
currently, when working with an OCaml project involving many dependencies, it is difficult to perform tests in a REPL (C-c C-s) with the proper packages loaded.
Granted, one can manually evaluate#use "topfind";;then#require "jwto";;or so for each package, but it quickly becomes cumbersome.
@yurug told me recently about the availability of dune utop, which is really cool!
However:
- it implies the project is managed by
dune(which may not be the case for a proof-of-concept development or so, with a single compilation unit and a.merlinlisting the libs directories) - it requires
utop, while I’d prefer a generic approach, just starting theocamlREPL in a vanilla tuareg+merlin setup when doingC-c C-s.
I had opened a related issue and proposed some workaround in auto-require packages when doing C-c C-s (tuareg issue #234), a refinement of which being pasted below:
Assume I want to automate a session that would interactively looks like:
#use "topfind";;
#thread;;
#require "lwt";;
#require "lwt.unix";;
#require "compiler-libs";;
#load "ocamlcommon.cma";;
#load "ocamlbytecomp.cma";;
and by automating, I mean just typing C-c C-s (or maybe C-u C-c C-s in tuareg) to get an equivalent REPL session.
The current workaround I have is to run in a terminal:
args=($(OCAMLFIND_COMMANDS='ocamlc=echo' ocamlfind ocamlc -linkpkg $(for arg in lwt lwt.unix compiler-libs; do echo "-package $arg"; done) -thread ocamlcommon.cma ocamlbytecomp.cma)); args[0]="ocaml"
rlwrap "${args[@]}"
(or run echo "${args[@]}" then copy-and-paste the full command in Tuareg’s prompt
OCaml REPL to run: [/usr/local/bin/opam config exec -- ocaml by default].)
As for the OCAMLFIND_COMMANDS='ocamlc=echo trick: it was related to the fact the -thread option is needed in ocamlfind’s command-line, but unlike ocamlfind ocamlc, ocaml does not support the -thread option… which is however added first in the arguments list, so it was feasible to override it.
Admittedly, this is hacky, but I guess the underlying use case can be important in one’s workflow; so I hope one such feature could be available soon in tuareg.
So, first sub-question:
would some of you be aware of simpler solutions to achieve this? (possible based on ocamlfind or opam, but not requiring utop)
Also, as I had mentioned in the issue #234, a starting-point for specifying the packages to load could be the .merlin file, but I believe there are typically no PKG lines in dune-generated .merlin files (if I’m not mistaken), so maybe some post-processing of the .merlin is needed.
Hence the second sub-question:
assuming merlin is installed and a .merlin file enumerates some additional directories to load, would it be feasible to use the existing elisp code of Merlin, or a ocamlmerlin command, to get the list of .cma files to load (and/or -I CLI flags) for the current buffer?