From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pBN8uuQL001529 for ; Fri, 23 Dec 2011 09:56:56 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkACAIFB9E5KfVK2i2dsb2JhbABEFptTkEUIIgEBAQoLCwcSBiGBcgEBAQQSAiwBGxILAQMMBgULDQ0hIgERAQUBChIGEwgKEIdgmhoKi2WCa4RkP4hxAgULg3KIEgSVAo19PYN7 X-IronPort-AV: E=Sophos;i="4.71,398,1320620400"; d="scan'208";a="136577179" Received: from mail-we0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Dec 2011 09:56:50 +0100 Received: by werb13 with SMTP id b13so7173685wer.27 for ; Fri, 23 Dec 2011 00:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=69Cx7DRXno3prD6QrXfMWsd4uIW+GcNITzTGIgDxO/w=; b=HqBhQRfMB/XysOXm6RChbr1Z6poCbOY37aC9mbcdiJyaIQX6IYbSg+myE2dMlU6noF Ez8Je1aTNMKEZCHxZ5FkGxHQHgBDob845I64jx6fmfKlsd4ciSyJyzdLwswTq9SAcryd VUAh2C8yt7WcTM2B/uhoKz0V4046v2DBwsxAY= Received: by 10.216.138.210 with SMTP id a60mr7531046wej.32.1324630517667; Fri, 23 Dec 2011 00:55:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.43.4 with HTTP; Fri, 23 Dec 2011 00:51:20 -0800 (PST) In-Reply-To: <4EF43609.6040609@rktmb.org> References: <4EF43609.6040609@rktmb.org> From: Gabriel Scherer Date: Fri, 23 Dec 2011 09:51:20 +0100 Message-ID: To: Mihamina Rakotomandimby Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id pBN8uuQL001529 Subject: Re: [Caml-list] Format OCaml Code Camlp4 parses Ocaml source, and can reprint it. You can't customize the output much, it's defined by the pretty-printer (but you could write your own pretty-printer), and it probably doesn't correspond to your own OCaml style. If you're only looking for a way to normalize indentation, you may be happy with that. camlp4o file.ml (* outputs in the console *) camlp4o file.ml -o output.ml Note that piping/redirection `camlp4o file.ml > foo` doesn't work as camlp4o sends a marshalled AST by default. An issue with camlp4 is that it can sometimes move comments a bit: the placement of comments in the reformatted source is approximative *with respect to whitespace* (you sometimes have a blank inserted between a phrase and the comment). That is not really an issue for the human reader, but it tends to confuse `ocamldoc`, which relies on whitespace heuristics to know which phrase a comment documents. You should think twice if you wish to use both camlp4 and ocamldoc at the same time. If you wanted to write your own pretty-printer (as a Camlp4 printer, or based on your own or another parser), you could be interested in: - The [Pprint] module of François Pottier, an interesting adaptation of Daan Leijen's Haskell PPrint library http://pauillac.inria.fr/~fpottier/ - The [easy-format] library of Martin Jambon http://martin.jambon.free.fr/easy-format.html - The [Format] module of the standard library http://caml.inria.fr/resources/doc/guides/format.en.html I have only used Format and Pprint, and prefer Pprint (simpler to understand and use). On Fri, Dec 23, 2011 at 9:04 AM, Mihamina Rakotomandimby wrote: > On 12/23/2011 10:57 AM, haihao shen wrote: >> >> Hi All, >> >> Does anyone know whether there is some tools or scripts to format ocaml >> code in a unified format? > > > If you mean having a "good" indentation, opening it in Emacs+tuareg-mode > then indenting will work fine. > > Note that it's a file by file way and it doesn not split uselessly long > lines to shorter ones: just indentation. Or I dont know how to fully use > tuareg-mode ;-). > > For a large set of files, I don't know how to ease the work. > > > -- > RMA. > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >