emacsocamlmerlin

How to make Merlin (OCaml) ignore some lines?


I use Merlin with Emacs to edit OCaml code. It normally works perfectly fine, but I wound the following problem:

I'm need to use a package, built by someone else, that adds to OCaml some keywords not native to the language. Since I use the package to compile the code, compilation works great. On the other hand Merlin goes crazy and thinks that the new keywords are an error. Luckily the new keywords only appear at the beginning of a line, so my code looks something like this:

let square x = x * x;;

let rec fact x =
    if x <= 1 then 1 else x * fact (x - 1);;

FOO "This syntax is not standard Ocaml" square fact;;

Where FOO is the new keyword. Merlin will complain and say Unbound constructor FOO. So the question is, can I make Marlin ignore that line? OR can you think of a hack to wrap the syntax in something Merlin won't complain about?


Solution

  • Merlin doesn't and will not (afaik) support arbitrary syntax extensions, but they do have parsing hacks for most commonly used camlp4 extensions like pa_lwt, pa_macro, etc. Also newest merlin versions will skip unknown lines and recover parsing, so that 'go-to-definition' and type throwback work on other parts of the file not modified by syntax extensions.