From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 6E5B87F89F for ; Mon, 24 Mar 2014 15:47:34 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jdimino@janestreet.com) identity=pra; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jdimino@janestreet.com"; x-sender="jdimino@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of jdimino@janestreet.com designates 38.105.200.229 as permitted sender) identity=mailfrom; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jdimino@janestreet.com"; x-sender="jdimino@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mx5.mail.janestreet.com) identity=helo; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jdimino@janestreet.com"; x-sender="postmaster@mx5.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArUBAPtEMFMmacjlnGdsb2JhbABZg0FXrAeNcoh0gRAeDgEBAQEBBhYJPIIlAQEBAwEnGQEBLAsBBAsLBAcaFgsiEgEFAQoSBhMSh1MDCQgDAgigAosYhFUBBZctA4cPEQaOdgQHhDiYToEyjxAYKYMdgT4 X-IPAS-Result: ArUBAPtEMFMmacjlnGdsb2JhbABZg0FXrAeNcoh0gRAeDgEBAQEBBhYJPIIlAQEBAwEnGQEBLAsBBAsLBAcaFgsiEgEFAQoSBhMSh1MDCQgDAgigAosYhFUBBZctA4cPEQaOdgQHhDiYToEyjxAYKYMdgT4 X-IronPort-AV: E=Sophos;i="4.97,721,1389740400"; d="scan'208";a="64465460" Received: from mx5.janestreet.com (HELO mx5.mail.janestreet.com) ([38.105.200.229]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Mar 2014 15:47:33 +0100 Received: from tot-oib-smtp1.delacy.com ([172.27.22.15] helo=tot-smtp) by mx5.mail.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1WS69z-0001ow-FT for caml-list@inria.fr; Mon, 24 Mar 2014 10:47:31 -0400 Received: from tot-dmz-mxgoog1.delacy.com ([172.27.224.14] helo=mxgoog2.janestreet.com) by tot-smtp with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1WS69z-0005j6-EA for caml-list@inria.fr; Mon, 24 Mar 2014 10:47:31 -0400 Received: from mail-ie0-f173.google.com ([209.85.223.173]) by mxgoog2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1WS69z-0003GP-AY for caml-list@inria.fr; Mon, 24 Mar 2014 10:47:31 -0400 Received: by mail-ie0-f173.google.com with SMTP id rl12so5609771iec.18 for ; Mon, 24 Mar 2014 07:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EAOLXB38diJs+q+yW1KGCWmbs4MBgGsnCljTObJiYhI=; b=BauhtPBgPqem0I8d2U9iQu86wD1heG9MPYneMEGKerGrRuM88JG2VVzvvrx3WqqLsL bIUQFpVat/upYQ06/rv9H16yZCDtY2u6ciA4uoXE+qoXe92SY71cEjTvRc0pz9kD1qIK ukPfuwbN5J9WdfwMtKvaKWDolCzmjp0s89f/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=EAOLXB38diJs+q+yW1KGCWmbs4MBgGsnCljTObJiYhI=; b=mJVtlQyB250+tRKXc8U/Xq9YrURl0HpqQbTVgJiwVPnk/aCKvAzqzHo5twaqRM+mIA ex7H49sBff1NUewNzyZ2HSQIS4t9yj+drz1VgQ07JtHRF9ivMELnjI77TgnFoGynDmtz MnJmL2atAn7mMp7HS3zaO0ioJ+387vx+3wy8PrmOeTHqkVt2OCuVJv7bw6TJzZbwtAdX RfrB2uxNgkR8Z+kCNEPNolH4R/nHmWc3mkudUvBekB2bhW/5f9x3J6qRRG9tOuP+Q92u qO/jgVNPxPmN3Vzd01lLZwt+dHWg7TnRsO6/05mSPzX1CGeiBPnuVYY5bpkSXwQBueir M+Pg== X-Gm-Message-State: ALoCoQmHBbh9Sdqh0yuuTd3cm/wAG+fXthxmIkpvYmXJKm+VUQ44Gv9hNeaRQ58ANkfuH/+ijmti+p5o3YDqK4Dpn7zMGDM/ZsTZRj1qmh8YW9qU0k+CSftx/KDxB/L4vJeonExeCjd6CZecKIfMCB0aRdL02viW+g== X-Received: by 10.42.39.6 with SMTP id f6mr938929ice.83.1395672450890; Mon, 24 Mar 2014 07:47:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.42.39.6 with SMTP id f6mr938920ice.83.1395672450770; Mon, 24 Mar 2014 07:47:30 -0700 (PDT) Received: by 10.50.114.38 with HTTP; Mon, 24 Mar 2014 07:47:30 -0700 (PDT) In-Reply-To: References: Date: Mon, 24 Mar 2014 14:47:30 +0000 Message-ID: From: Jeremie Dimino To: Alan Schmitt Cc: OCaml Mailing List Content-Type: multipart/alternative; boundary=90e6ba61493ca6bbdf04f55b50c9 Subject: Re: [Caml-list] ocaml toplevel: is it possible to separate what is sent on stdout from the answers from the toplevel? --90e6ba61493ca6bbdf04f55b50c9 Content-Type: text/plain; charset=ISO-8859-1 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 --90e6ba61493ca6bbdf04f55b50c9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
The best way is to create a custom toplevel and map t= he replies.

"val x : int =3D 3" is print= ed 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 m= essages on the formatter passed to
[Toploop.loop], which is [Format.std_formatter] by default. So you can=
either:
(1) override [Format.std_formatter] callbacks<= /div>
(2) call [Toploop.loop] with a custom formatter

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

= =A0 =A0 Toploop.toplevel_startup_hook :=3D (fun () -> Toploop.loop my_fo= rmatter; exit 0)

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

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



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

I'm looking into extending the OCaml support in org-mode, and to do so<= br> 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
=3D 3" in the following interaction:

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

Is there a way to do it?

Thanks,

Alan

--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://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
--90e6ba61493ca6bbdf04f55b50c9--