caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Format OCaml Code
@ 2011-12-23  7:57 haihao shen
  2011-12-23  8:04 ` Mihamina Rakotomandimby
  2011-12-24  8:35 ` Jun Furuse
  0 siblings, 2 replies; 9+ messages in thread
From: haihao shen @ 2011-12-23  7:57 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 134 bytes --]

Hi All,

Does anyone know whether there is some tools or scripts to format ocaml
code in a unified format?

Thanks in advance,
Haihao

[-- Attachment #2: Type: text/html, Size: 154 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  7:57 [Caml-list] Format OCaml Code haihao shen
@ 2011-12-23  8:04 ` Mihamina Rakotomandimby
  2011-12-23  8:51   ` Gabriel Scherer
  2011-12-24  3:48   ` Francois¡¡Charles Matthieu¡¡Berenger
  2011-12-24  8:35 ` Jun Furuse
  1 sibling, 2 replies; 9+ messages in thread
From: Mihamina Rakotomandimby @ 2011-12-23  8:04 UTC (permalink / raw)
  To: caml-list

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  8:04 ` Mihamina Rakotomandimby
@ 2011-12-23  8:51   ` Gabriel Scherer
  2011-12-23 12:27     ` rixed
  2011-12-23 17:01     ` Jérémie Dimino
  2011-12-24  3:48   ` Francois¡¡Charles Matthieu¡¡Berenger
  1 sibling, 2 replies; 9+ messages in thread
From: Gabriel Scherer @ 2011-12-23  8:51 UTC (permalink / raw)
  To: Mihamina Rakotomandimby; +Cc: caml-list

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
<mihamina@rktmb.org> 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
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  8:51   ` Gabriel Scherer
@ 2011-12-23 12:27     ` rixed
  2011-12-23 12:49       ` Jérémie Dimino
  2011-12-23 17:01     ` Jérémie Dimino
  1 sibling, 1 reply; 9+ messages in thread
From: rixed @ 2011-12-23 12:27 UTC (permalink / raw)
  To: caml-list

> Note that piping/redirection `camlp4o file.ml > foo` doesn't work as
> camlp4o sends a marshalled AST by default.

This is indeed annoying.
Unfortunately, and quite surprisingly to me, using -o /dev/stdout does
not help.

> 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).

I've seen a comment in a record initialization (to comment on
a given field) moved far away, after the end of the record.
Here is an exemple :

---
type record = { a : int; b : int; c : int }
let r1 = {
	a = 0 ;
	b = 1 ; (* This is about b *)
	c = 2 }
---

where the comment disapear. While in this one :

---
type record = { a : int ; b : int ; c : int }
let r1 = {
        a = 0 ;
        b = 1 ; (* This is about b *)
        c = 2 } and
    r2 = { a = 0 ; b = 1 ; c = 2 }
---

the comment is moved after initialization of r1. :-(


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23 12:27     ` rixed
@ 2011-12-23 12:49       ` Jérémie Dimino
  0 siblings, 0 replies; 9+ messages in thread
From: Jérémie Dimino @ 2011-12-23 12:49 UTC (permalink / raw)
  To: rixed; +Cc: caml-list

Le vendredi 23 décembre 2011 à 13:27 +0100, rixed@happyleptic.org a
écrit :
> > Note that piping/redirection `camlp4o file.ml > foo` doesn't work as
> > camlp4o sends a marshalled AST by default.
> 
> This is indeed annoying.
> Unfortunately, and quite surprisingly to me, using -o /dev/stdout does
> not help.

You can force camlp4 to use the pretty-printer with:

  camlp4o -printer o file.ml > foo

-- 
Jérémie



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  8:51   ` Gabriel Scherer
  2011-12-23 12:27     ` rixed
@ 2011-12-23 17:01     ` Jérémie Dimino
  1 sibling, 0 replies; 9+ messages in thread
From: Jérémie Dimino @ 2011-12-23 17:01 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: Mihamina Rakotomandimby, caml-list

Le vendredi 23 décembre 2011 à 09:51 +0100, Gabriel Scherer a écrit :
> 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.

Note that ocamldoc does not use the pretty-printed output of camlp4. It
uses locations in the ast and comments are fetched from the original
file.

Cheers,

-- 
Jérémie



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  8:04 ` Mihamina Rakotomandimby
  2011-12-23  8:51   ` Gabriel Scherer
@ 2011-12-24  3:48   ` Francois¡¡Charles Matthieu¡¡Berenger
  1 sibling, 0 replies; 9+ messages in thread
From: Francois¡¡Charles Matthieu¡¡Berenger @ 2011-12-24  3:48 UTC (permalink / raw)
  To: caml-list


On Fri, 23 Dec 2011 11:04:25 +0300
Mihamina Rakotomandimby <mihamina@rktmb.org> 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.

Run emacs in batch mode.
I never did it myself but I know it is possible.
The script consist of elisp commands I guess.

Regards,
F.

> 
> -- 
> 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
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-23  7:57 [Caml-list] Format OCaml Code haihao shen
  2011-12-23  8:04 ` Mihamina Rakotomandimby
@ 2011-12-24  8:35 ` Jun Furuse
  2011-12-24  9:03   ` haihao shen
  1 sibling, 1 reply; 9+ messages in thread
From: Jun Furuse @ 2011-12-24  8:35 UTC (permalink / raw)
  To: haihao shen; +Cc: caml-list

Hi,
ocaml-indent may help you, at least around indentations:
 https://bitbucket.org/camlspotter/ocaml-indent/wiki/Home
Jun
On Fri, Dec 23, 2011 at 3:57 PM, haihao shen <haihaoshen@gmail.com> wrote:
> Hi All,
>
> Does anyone know whether there is some tools or scripts to format ocaml code
> in a unified format?
>
> Thanks in advance,
> Haihao


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Format OCaml Code
  2011-12-24  8:35 ` Jun Furuse
@ 2011-12-24  9:03   ` haihao shen
  0 siblings, 0 replies; 9+ messages in thread
From: haihao shen @ 2011-12-24  9:03 UTC (permalink / raw)
  To: Jun Furuse; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 460 bytes --]

Thanks Jun.

On Sat, Dec 24, 2011 at 4:35 PM, Jun Furuse <jun.furuse@gmail.com> wrote:

> Hi,
> ocaml-indent may help you, at least around indentations:
>  https://bitbucket.org/camlspotter/ocaml-indent/wiki/Home
> Jun
> On Fri, Dec 23, 2011 at 3:57 PM, haihao shen <haihaoshen@gmail.com> wrote:
> > Hi All,
> >
> > Does anyone know whether there is some tools or scripts to format ocaml
> code
> > in a unified format?
> >
> > Thanks in advance,
> > Haihao
>

[-- Attachment #2: Type: text/html, Size: 958 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-12-24  9:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-23  7:57 [Caml-list] Format OCaml Code haihao shen
2011-12-23  8:04 ` Mihamina Rakotomandimby
2011-12-23  8:51   ` Gabriel Scherer
2011-12-23 12:27     ` rixed
2011-12-23 12:49       ` Jérémie Dimino
2011-12-23 17:01     ` Jérémie Dimino
2011-12-24  3:48   ` Francois¡¡Charles Matthieu¡¡Berenger
2011-12-24  8:35 ` Jun Furuse
2011-12-24  9:03   ` haihao shen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).