Discussion:
[Caml-list] ocp-indent begin/end behaviour?
(too old to reply)
Malcolm Matalka
2016-09-15 19:01:16 UTC
Permalink
I have the following code that I'm using ocp-indent to indent:

let () =
match Random.int 10 with
| 1 -> begin
zoom ();
baz ()
end
| 2 ->
()

The zoom and baz are indented "double", and I cannot figure out how to
undo that. I'd like the begin/end to have no effect on indentation at
all. Is this a bug or am I doing something wrong?

/Malcolm
--
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
Goswin von Brederlow
2016-09-19 09:39:30 UTC
Permalink
Post by Malcolm Matalka
let () =
match Random.int 10 with
| 1 -> begin
zoom ();
baz ()
end
| 2 ->
()
The zoom and baz are indented "double", and I cannot figure out how to
undo that. I'd like the begin/end to have no effect on indentation at
all. Is this a bug or am I doing something wrong?
/Malcolm
Double seems right since the match case indents and begin/end also
needs to indent since it creates a sub block. Consider this:

let () =
match Random.int 10 with
| 1 ->
bar ();
begin
zoom ();
baz ()
end;
foo ()
| 2 ->
()

Note: The only reason to use begin/end for a match case is if you have
another match inside I believe.

MfG
Goswin
--
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
Louis Gesbert
2016-10-03 07:58:50 UTC
Permalink
Post by Malcolm Matalka
let () =
match Random.int 10 with
| 1 -> begin
zoom ();
baz ()
end
| 2 ->
()
The zoom and baz are indented "double", and I cannot figure out how to
undo that. I'd like the begin/end to have no effect on indentation at
all. Is this a bug or am I doing something wrong?
/Malcolm
ocp-indent is all about compromises and trying to keep programs visually
consistent. Also, it attempts to keep the configuration options to a minimum
so that their effects can still be easily understood, and styles don't diverge
too much.

In this case, `zoom (); baz ()` is inside two scopes that can be closed
individually (`->` and `begin/end`). So, as Goswin pointed out, without that
extra indentation the `end` would have to be either at the level of the `|` or
that of `zoom ();`, which isn't totally accurate, and in either case, if you
were to add `; some more stuff` after `end`, you couldn't get a proper
indentation without backtracking anymore.

So it's not a bug, but a design choice -- it's impossible to satisfy everyone
anyway (-- or it would end up like LaTeX). Note that it's designed to play
well with interactive use + partially manual indent (e.g. if you move `zoom
();`, `baz ()` will follow)

Best,
Louis Gesbert -- OCamlPro
--
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
Loading...