From: Jeremie Dimino <jdimino@janestreet.com>
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] ocaml toplevel: is it possible to separate what is sent on stdout from the answers from the toplevel?
Date: Mon, 24 Mar 2014 14:47:30 +0000 [thread overview]
Message-ID: <CANhEzE6AyCjw4dEF2K_R8=Q9tFZtPo196+G+5Sj958aUHeVuMw@mail.gmail.com> (raw)
In-Reply-To: <m2r45rzqez.fsf@polytechnique.org>
[-- Attachment #1: Type: text/plain, Size: 1903 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 2962 bytes --]
next prev parent reply other threads:[~2014-03-24 14:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-24 13:17 Alan Schmitt
2014-03-24 14:47 ` Jeremie Dimino [this message]
2014-03-29 11:02 ` Alan Schmitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANhEzE6AyCjw4dEF2K_R8=Q9tFZtPo196+G+5Sj958aUHeVuMw@mail.gmail.com' \
--to=jdimino@janestreet.com \
--cc=alan.schmitt@polytechnique.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox