Reputation: 10204
I am reading Ocaml Style guide on nested let-in of Ocaml.
It is suggested that
Indenting nested let expressions: Blocks of code that have nested let expressions should not be indented. Bad:
let x = exp1 in
let y = exp2 in
x + y
Good:
let x = exp1 in
let y = exp2 in
x + y
However, what do you think about how to indent my following program.
let f =
let g = 3 in
g + 2
The above is indented by emacs. But apparently, this indenting of emacs violates the style guide I cited earlier. To follow the style, shouldn' t it be more like this one?
let f =
let g = 3 in
g + 2
Thank you for your ideas.
@Gilles: In my current default Tuareg mode, I get such indenting, which is diffrent from yours
let f =
let g = 3 in
let h = 4 in
g + 2
could you explain which configuration should I do to make my Tuareg mode indent as yours?
Upvotes: 5
Views: 1467
Reputation: 107759
The official caml-mode
(part of the standard Ocaml distribution) defaults to not intenting the body of a let
expression:
let f =
let g = 3 in
let h = 4 in
g + 2
This is the style used by the authors of Ocaml (hence the Right style). In my experience the official mode matches the official style very well (unsurprising since it's from the same people). If you're getting something different, you (or the person or distribution who installed the mode on your machine) must have configured it.
Tuareg mode puts the same indentation on the snippet above on my machine (Debian squeeze). Different versions have different indentation defaults; in particular, this is the docstring for tuareg-in-indent
on 2.0.1:
How many spaces to indent from a
in
keyword.
Upstream recommends 0, and this is what we default to since 2.0.1 instead of the historicaltuareg-default-indent
.
Upvotes: 5
Reputation: 10204
I think Tuareg does have some strange behavior indenting nested let-in. add these lines to come back to "default" ocaml indenting style, suggested by C. TROESTLER
(add-hook 'tuareg-mode-hook
(function (lambda ()
(setq tuareg-in-indent 0)
(setq tuareg-let-always-indent t)
(setq tuareg-let-indent tuareg-default-indent)
(setq tuareg-with-indent 0)
(setq tuareg-function-indent 0)
(setq tuareg-fun-indent 0)
(setq tuareg-parser-indent 0)
(setq tuareg-match-indent 0)
(setq tuareg-begin-indent tuareg-default-indent)
(setq tuareg-parse-indent tuareg-default-indent); .mll
(setq tuareg-rule-indent tuareg-default-indent)
(setq tuareg-font-lock-symbols nil)
)))
Upvotes: 3