I’m currently working with some code using camlp4r.
When I use the Emacs buffer with Tuareg mode, and I call ocaml (Run OCaml REPL or Evaluate phrase), it’s ok when using ordinary/normal OCaml syntax (directive #camlp4o).
However, when using the revised syntax (directive #camlp4r), which accepts only one semi-colon for ending a phrase, there is a confusion because the REPL is still expecting a double semicolon to evaluate the phrase. And if I give it one, there is of course a parse error:
Parse error: ';' expected after [str_item] (in [phrase])
It’s the same error if the phrase is sent from the buffer or directly written in the toplevel. So there is no problem with passing the phrase but with this unexpected “end of phrase” lexem in the Toplevel.
It works perfectly when writing the same phrase in a basic CLI Toplevel (
$ ocaml then directive
I’m surprised because #camlp4o and #camlp4r are ordinary topfind directives.
How can I fix that?
I’m not really aware of all the toplevel machinery. I just know that there are toploop.ml topdirs.ml topmain.ml files in ocaml/toplevel that could be related to that.
I had a look at tuareg.el that handles shortcuts (e.g. shift return, ctrl return to insert “;;”) and seems to send the phrase to the REPL:
(defun tuareg-interactive-send-input () "Send the current phrase to the OCaml REPL or insert a newline. If the point is next to \";;\", the phrase is sent to the REPL, otherwise a newline is inserted and the lines are indented."
But it’s still unclear how I could change/fix this (while keeping the behaviour for normal/ordinary syntax). In fact, I don’t know which component is responsible for handling that.