@@ -86,6 +86,7 @@ let conventional_profile from =
8686 ; let_binding_deindent_fun= elt true
8787 ; let_binding_spacing= elt `Compact
8888 ; let_module= elt `Compact
89+ ; letop_punning= elt `Preserve
8990 ; line_endings= elt `Lf
9091 ; margin= elt 80
9192 ; match_indent= elt 0
@@ -156,6 +157,7 @@ let ocamlformat_profile from =
156157 ; let_binding_deindent_fun= elt true
157158 ; let_binding_spacing= elt `Compact
158159 ; let_module= elt `Compact
160+ ; letop_punning= elt `Preserve
159161 ; line_endings= elt `Lf
160162 ; margin= elt 80
161163 ; match_indent= elt 0
@@ -225,6 +227,7 @@ let janestreet_profile from =
225227 ; let_binding_deindent_fun= elt false
226228 ; let_binding_spacing= elt `Double_semicolon
227229 ; let_module= elt `Sparse
230+ ; letop_punning= elt `Preserve
228231 ; line_endings= elt `Lf
229232 ; margin= elt 90
230233 ; match_indent= elt 0
@@ -994,6 +997,27 @@ module Formatting = struct
994997 (fun conf elt -> update conf ~f: (fun f -> {f with let_module= elt}))
995998 (fun conf -> conf.fmt_opts.let_module)
996999
1000+ let letop_punning =
1001+ let doc = " Name punning in bindings using extended let operators." in
1002+ let names = [" letop-punning" ] in
1003+ let all =
1004+ [ Decl.Value. make ~name: " preserve" `Preserve
1005+ " $(b,preserve) uses let-punning only when it exists in the \
1006+ source; the code \" $(i,let* foo and* z = z in ...)\" will be \
1007+ left unchanged."
1008+ ; Decl.Value. make ~name: " always" `Always
1009+ " $(b,always) uses let-punning whenever possible; the code \
1010+ \" $(i,let* foo and* z = z in ...)\" will be rewritten to \
1011+ \" $(i,let* foo and* z in ...)\" ."
1012+ ; Decl.Value. make ~name: " never" `Never
1013+ " $(b,never) never uses let-punning; the code \" $(i,let* foo and* \
1014+ z = z in ...)\" will be rewritten to \" $(i,let* foo = foo and* z \
1015+ = z in ...)\" . " ]
1016+ in
1017+ Decl. choice ~names ~all ~default ~doc ~kind
1018+ (fun conf elt -> update conf ~f: (fun f -> {f with letop_punning= elt}))
1019+ (fun conf -> conf.fmt_opts.letop_punning)
1020+
9971021 let let_open =
9981022 let names = [" let-open" ] in
9991023 let msg = concrete_syntax_preserved_msg in
@@ -1353,6 +1377,7 @@ module Formatting = struct
13531377 ; elt let_binding_deindent_fun
13541378 ; elt let_binding_spacing
13551379 ; elt let_module
1380+ ; elt letop_punning
13561381 ; elt line_endings
13571382 ; elt margin
13581383 ; elt match_indent
0 commit comments