The best way is to create a custom toplevel and map the replies.

"val x : int = 3" is printed using [Toploop.print_out_phrase] which is
a reference, so you can replace by a function adding markers around
the text.

This won't catch error/warning messages. If you also want to
distinguish these, you can redirect the standard formatters. The
toplevel prints replies and error messages on the formatter passed to
[Toploop.loop], which is [Format.std_formatter] by default. So you can
either:
(1) override [Format.std_formatter] callbacks
(2) call [Toploop.loop] with a custom formatter

You can do (1) with [Format.pp_set_all_formatter_output_functions] and
(2) by setting the startup hook:

    Toploop.toplevel_startup_hook := (fun () -> Toploop.loop my_formatter; exit 0)

Warnings are always printed on [Format.err_formatter] so you'll need
to override its callbacks.

If you can't create a custom toplevel, I guess you can also send the
code to the toplevel at the beginning of the session.



On Mon, Mar 24, 2014 at 1:17 PM, Alan Schmitt <alan.schmitt@polytechnique.org> wrote:
Hello,

I'm looking into extending the OCaml support in org-mode, and to do so
I would like to distinguish what is printed out as replies from the
toplevel from the data printed from the program.

To give a precise example, I would like to split "foo" from "val x : int
= 3" in the following interaction:

--8<---------------cut here---------------start------------->8---
# let x = print_endline "foo"; 3;;
foo
val x : int = 3
--8<---------------cut here---------------end--------------->8---

Is there a way to do it?

Thanks,

Alan

--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
Jeremie