tags:

views:

260

answers:

2

I have ~30.000 lines of badly indented OCaml code (including mly and mll files) and would like to indent them. I tried googling for variations of 'ocaml indent' the closest I can get is to use Omlet.vim and indent the code one line at a time (via C-f in insert mode). Is there a way to do the indentation for all the 30000 lines?

+7  A: 

I use Emacs as my editor with this package installed:

http://caml.inria.fr/pub/docs/u3-ocaml/emacs/index.html

To indent existing code you need to highlight it and then use the key combination C-M-\

You can script this per file pretty easily and I find the indentation to be pretty good.

chollida
Thank you, that worked.
vbigiani
You can do the same thing in tuareg-mode with `M-q`. Don't know how it scales to thousands of lines though.
Chris Conway
@Chris, you're correct. I did use tuareg when I started learning OCaml and I do think it's more popular than the package hosted on the inria site. I just happen to prefer the package I posted. But take that with a grain of salt as I'm not the most polished OCaml programmer around;)
chollida
+1  A: 

When I want to re-indent a whole file in vim, I use the following key sequence:

g g V =

Breaking this down for you, g g moves the cursor to the beginning of the file. V enters visual mode. = indents the selected lines.

This should be much faster than your method of applying indentation line by line, but yet will use the same rules (warning: using Omlet, indenting a whole file may take a while).

a_m0d