forked from janestreet/ocamlformat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConf.ml
2234 lines (2086 loc) · 79.9 KB
/
Conf.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(**************************************************************************)
(* *)
(* OCamlFormat *)
(* *)
(* Copyright (c) Facebook, Inc. and its affiliates. *)
(* *)
(* This source code is licensed under the MIT license found in *)
(* the LICENSE file in the root directory of this source tree. *)
(* *)
(**************************************************************************)
(** Configuration options *)
type t =
{ align_cases: bool
; align_constructors_decl: bool
; align_variants_decl: bool
; assignment_operator: [`Begin_line | `End_line]
; break_before_in: [`Fit_or_vertical | `Auto]
; break_cases: [`Fit | `Nested | `Toplevel | `Fit_or_vertical | `All]
; break_collection_expressions: [`Wrap | `Fit_or_vertical]
; break_infix: [`Wrap | `Fit_or_vertical]
; break_infix_before_func: bool
; break_fun_decl: [`Wrap | `Fit_or_vertical | `Smart]
; break_fun_sig: [`Wrap | `Fit_or_vertical | `Smart]
; break_separators: [`Before | `After]
; break_sequences: bool
; break_string_literals: [`Auto | `Never]
; break_struct: bool
; cases_exp_indent: int
; cases_matching_exp_indent: [`Normal | `Compact]
; comment_check: bool
; disable: bool
; disambiguate_non_breaking_match: bool
; doc_comments: [`Before | `Before_except_val | `After_when_possible]
; doc_comments_padding: int
; doc_comments_tag_only: [`Fit | `Default]
; dock_collection_brackets: bool
; exp_grouping: [`Parens | `Preserve]
; extension_indent: int
; field_space: [`Tight | `Loose | `Tight_decl]
; function_indent: int
; function_indent_nested: [`Always | `Auto | `Never]
; if_then_else: [`Compact | `Fit_or_vertical | `Keyword_first | `K_R]
; indent_after_in: int
; indicate_multiline_delimiters: [`No | `Space | `Closing_on_separate_line]
; indicate_nested_or_patterns: [`Space | `Unsafe_no]
; infix_precedence: [`Indent | `Parens]
; leading_nested_match_parens: bool
; let_and: [`Compact | `Sparse]
; let_binding_indent: int
; let_binding_spacing: [`Compact | `Sparse | `Double_semicolon]
; let_module: [`Compact | `Sparse]
; margin: int
; match_indent: int
; match_indent_nested: [`Always | `Auto | `Never]
; max_indent: int option
; max_iters: int
; module_item_spacing: [`Compact | `Preserve | `Sparse]
; nested_match: [`Wrap | `Align]
; ocp_indent_compat: bool
; parens_ite: bool
; parens_tuple: [`Always | `Multi_line_only]
; parens_tuple_patterns: [`Always | `Multi_line_only]
; parse_docstrings: bool
; quiet: bool
; sequence_blank_line: [`Compact | `Preserve_one]
; sequence_style: [`Before | `Separator | `Terminator]
; single_case: [`Compact | `Sparse]
; space_around_arrays: bool
; space_around_lists: bool
; space_around_records: bool
; space_around_variants: bool
; stritem_extension_indent: int
; type_decl: [`Compact | `Sparse]
; type_decl_indent: int
; wrap_comments: bool
; wrap_fun_args: bool }
let profile_option_names = ["p"; "profile"]
open Cmdliner
let warn_raw, collect_warnings =
let delay_warning = ref false in
let delayed_warning_list = ref [] in
let warn_ s =
if !delay_warning then delayed_warning_list := s :: !delayed_warning_list
else Format.eprintf "%s" s
in
let collect_warnings f =
let old_flag, old_list = (!delay_warning, !delayed_warning_list) in
delay_warning := true ;
delayed_warning_list := [] ;
let res = f () in
let collected = List.rev !delayed_warning_list in
delay_warning := old_flag ;
delayed_warning_list := old_list ;
(res, fun () -> List.iter ~f:warn_ collected)
in
(warn_, collect_warnings)
let warn ?filename ?lnum fmt =
Format.kasprintf
(fun s ->
let loc : string =
match (filename, lnum) with
| Some file, Some lnum ->
Format.asprintf "File %a, line %d:@\n" Fpath.pp file lnum
| Some file, None -> Format.asprintf "File %a@\n" Fpath.pp file
| None, _ -> ""
in
warn_raw (Format.asprintf "%sWarning: %s@\n" loc s) )
fmt
module C = Config_option.Make (struct
type config = t
let profile_option_names = profile_option_names
let warn (config : config) fmt =
Format.kasprintf (fun s -> if not config.quiet then warn "%s" s) fmt
end)
let info =
let doc = "A tool to format OCaml code." in
let man =
[ `S Cmdliner.Manpage.s_description
; `P "$(tname) automatically formats OCaml code."
; `S (C.section_name `Formatting)
; `P
"Unless otherwise noted, any option \
$(b,--)$(i,option)$(b,=)$(i,VAL) detailed in this section can be \
set in many ways, its value is determined in the following order \
(of increasing priority): the default value is used if no other \
value is specified. The value of a boolean option $(b,--foo) or \
$(b,--no-foo) can be modified in an $(b,.ocamlformat) \
configuration file with '$(b,foo = ){$(b,true),$(b,false)}', it \
can be done for any other option with an '$(b,option = )$(i,VAL)' \
line (*), or using the OCAMLFORMAT environment variable: \
$(b,OCAMLFORMAT=)$(i,option)$(b,=)$(i,VAL)$(b,,)...$(b,,)$(i,option)$(b,=)$(i,VAL), \
or as an optional parameter on the command line, or with a global \
$(b,[@@@ocamlformat \")$(i,option)$(b,=)$(i,VAL)$(b,\"]) attribute \
in the processed file, or with an $(b,[@@ocamlformat \
\")$(i,option)$(b,=)$(i,VAL)$(b,\"]) attribute on expression in \
the processed file."
; `P
"(*) $(b,.ocamlformat) files in current and all ancestor \
directories for each input file are used, as well as the global \
$(b,ocamlformat) file defined in $(b,\\$XDG_CONFIG_HOME) or in \
$(b,\\$HOME/.config) if $(b,\\$XDG_CONFIG_HOME) is undefined. The \
global $(b,ocamlformat) file has the lowest priority, then the \
closer the directory is to the processed file, the higher the \
priority. The global $(b,ocamlformat) file is only used when the \
option $(b,enable-outside-detected-project) is set."
; `P
"If the $(b,disable) option is not set, an $(b,.ocamlformat-ignore) \
file specifies files that OCamlFormat should ignore. Each line in \
an $(b,.ocamlformat-ignore) file specifies a filename relative to \
the directory containing the $(b,.ocamlformat-ignore) file. \
Shell-style regular expressions are supported. Lines starting with \
$(b,#) are ignored and can be used as comments."
; `P
"If the $(b,disable) option is set, an $(b,.ocamlformat-enable) \
file specifies files that OCamlFormat should format even when the \
$(b,disable) option is set. Each line in an \
$(b,.ocamlformat-enable) file specifies a filename relative to the \
directory containing the $(b,.ocamlformat-enable) file. \
Shell-style regular expressions are supported. Lines starting with \
$(b,#) are ignored and can be used as comments." ]
in
Term.info "ocamlformat" ~version:Version.version ~doc ~man
(** Options affecting formatting *)
module Formatting = struct
let section = `Formatting
let align_cases =
let doc = "Align match/try cases vertically." in
let names = ["align-cases"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with align_cases= x})
(fun conf -> conf.align_cases)
let align_constructors_decl =
let doc = "Align type declarations vertically." in
let names = ["align-constructors-decl"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with align_constructors_decl= x})
(fun conf -> conf.align_constructors_decl)
let align_variants_decl =
let doc = "Align type variants declarations vertically." in
let names = ["align-variants-decl"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with align_variants_decl= x})
(fun conf -> conf.align_variants_decl)
let assignment_operator =
let doc = "Position of the assignment operator." in
let names = ["assignment-operator"] in
let all =
[ ( "end-line"
, `End_line
, "$(b,end-line) positions assignment operators (`:=` and `<-`) at \
the end of the line and breaks after it if the whole assignment \
expression does not fit on a single line." )
; ( "begin-line"
, `Begin_line
, "$(b,begin-line) positions assignment operators (`:=` and `<-`) \
at the beginning of the line and breaks before it if the whole \
assignment expression does not fit on a single line." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with assignment_operator= x})
(fun conf -> conf.assignment_operator)
let break_before_in =
let doc =
"Whether the line should break before the $(i,in) keyword of a \
$(i,let) binding."
in
let names = ["break-before-in"] in
let all =
[ ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) will always break the line before the \
$(i,in) keyword if the whole $(i,let) binding does not fit on a \
single line." )
; ( "auto"
, `Auto
, "$(b,auto) will only break the line if the $(i,in) keyword does \
not fit on the previous line." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_before_in= x})
(fun conf -> conf.break_before_in)
let break_cases =
let doc = "Break pattern match cases." in
let names = ["break-cases"] in
let all =
[ ( "fit"
, `Fit
, "Specifying $(b,fit) lets pattern matches break at the margin \
naturally." )
; ( "nested"
, `Nested
, "$(b,nested) forces a break after nested or-patterns to highlight \
the case body. Note that with $(b,nested), the \
$(b,indicate-nested-or-patterns) option is not needed, and so \
ignored." )
; ( "toplevel"
, `Toplevel
, "$(b,toplevel) forces top-level cases (i.e. not nested \
or-patterns) to break across lines, otherwise break naturally at \
the margin." )
; ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) tries to fit all or-patterns on the same \
line, otherwise breaks." )
; ( "all"
, `All
, "$(b,all) forces all pattern matches to break across lines." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_cases= x})
(fun conf -> conf.break_cases)
let break_collection_expressions =
let doc =
"Break collection expressions (lists and arrays) elements by elements."
in
let names = ["break-collection-expressions"] in
let all =
[ ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) vertically breaks expressions if they do \
not fit on a single line." )
; ( "wrap"
, `Wrap
, "$(b,wrap) will group simple expressions and try to format them \
in a single line." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_collection_expressions= x})
(fun conf -> conf.break_collection_expressions)
let break_fun_decl =
let doc = "Style for function declarations and types." in
let names = ["break-fun-decl"] in
let all =
[ ("wrap", `Wrap, "$(b,wrap) breaks only if necessary.")
; ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) vertically breaks arguments if they do not \
fit on a single line." )
; ( "smart"
, `Smart
, "$(b,smart) is like $(b,fit-or-vertical) but try to fit arguments \
on their line if they fit." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_fun_decl= x})
(fun conf -> conf.break_fun_decl)
let break_fun_sig =
let doc = "Style for function signatures." in
let names = ["break-fun-sig"] in
let all =
[ ("wrap", `Wrap, "$(b,wrap) breaks only if necessary.")
; ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) vertically breaks arguments if they do not \
fit on a single line." )
; ( "smart"
, `Smart
, "$(b,smart) is like $(b,fit-or-vertical) but try to fit arguments \
on their line if they fit." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_fun_sig= x})
(fun conf -> conf.break_fun_sig)
let break_infix =
let doc = "Break sequence of infix operators." in
let names = ["break-infix"] in
let all =
[ ( "wrap"
, `Wrap
, "$(b,wrap) will group simple expressions and try to format them \
in a single line." )
; ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) vertically breaks expressions if they do \
not fit on a single line." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_infix= x})
(fun conf -> conf.break_infix)
let break_infix_before_func =
let doc =
"Break infix operators whose right arguments are anonymous functions \
specially: do not break after the operator so that the first line of \
the function appears docked at the end of line after the operator."
in
let names = ["break-infix-before-func"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with break_infix_before_func= x})
(fun conf -> conf.break_infix_before_func)
let break_separators =
let doc =
"Break before or after separators such as `;` in list or record \
expressions."
in
let names = ["break-separators"] in
let all =
[ ( "after"
, `After
, "$(b,after) breaks the expressions after the separator." )
; ( "before"
, `Before
, "$(b,before) breaks the expressions before the separator." ) ]
in
C.choice ~names ~all ~doc ~section
~removed_values:
[ C.removed_value ~name:"after-and-docked" ~version:"0.12"
~msg:
"One can get a similar behaviour by setting \
`break-separators=after`, `space-around-lists=false`, and \
`dock-collection-brackets=false`." ]
(fun conf x -> {conf with break_separators= x})
(fun conf -> conf.break_separators)
let break_sequences =
let doc =
"Force sequence expressions to break irrespective of margin."
in
let names = ["break-sequences"] in
C.flag ~default:true ~names ~doc ~section
(fun conf x -> {conf with break_sequences= x})
(fun conf -> conf.break_sequences)
let break_string_literals =
let doc = "Break string literals." in
let names = ["break-string-literals"] in
let all =
[ ( "auto"
, `Auto
, "$(b,auto) mode breaks lines at newlines and wraps string \
literals at the margin." )
; ( "never"
, `Never
, "$(b,never) mode formats string literals as they are parsed, in \
particular, with escape sequences expanded." ) ]
in
C.choice ~names ~all ~doc ~section
~removed_values:
(C.removed_values
~names:["newlines"; "newlines-and-wrap"; "wrap"]
~version:"0.12"
~msg:
"It has been replaced by the new default `auto` value, which \
breaks lines at newlines and wraps string literals at the \
margin." )
(fun conf x -> {conf with break_string_literals= x})
(fun conf -> conf.break_string_literals)
let break_struct =
let doc = "Break struct-end module items." in
let names = ["break-struct"] in
let all =
[ ( "force"
, `Force
, "$(b,force) will break struct-end phrases unconditionally." )
; ( "natural"
, `Natural
, "$(b,natural) will break struct-end phrases naturally at the \
margin." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with break_struct= Poly.(x = `Force)})
(fun conf -> if conf.break_struct then `Force else `Natural)
let cases_exp_indent =
let docv = "COLS" in
let doc =
"Indentation of cases expressions ($(docv) columns). See also the \
$(b,cases-matching-exp-indent) and $(b,nested-match) options."
in
let names = ["cases-exp-indent"] in
C.any Arg.int ~names ~default:4 ~doc ~docv ~section ~allow_inline:false
(fun conf x -> {conf with cases_exp_indent= x})
(fun conf -> conf.cases_exp_indent)
let cases_matching_exp_indent =
let doc =
"Indentation of cases right-hand sides which are `match` or `try` \
expressions."
in
let names = ["cases-matching-exp-indent"] in
let all =
[ ( "normal"
, `Normal
, "$(b,normal) indents as it would any other expression." )
; ( "compact"
, `Compact
, "$(b,compact) forces an indentation of 2, unless \
$(b,nested-match) is set to $(b,align) and we're on the last \
case." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with cases_matching_exp_indent= x})
(fun conf -> conf.cases_matching_exp_indent)
let disable =
let doc =
"Disable ocamlformat. This is used in attributes to locally disable \
automatic code formatting. One can also use $(b,[@@@ocamlformat \
\"enable\"]) instead of $(b,[@@@ocamlformat \"disable=false\"])."
in
C.flag ~names:["disable"] ~default:false ~doc ~section
(fun conf x -> {conf with disable= x})
(fun conf -> conf.disable)
let disambiguate_non_breaking_match =
let doc =
"Add parentheses around matching constructs that fit on a single line."
in
C.flag
~names:["disambiguate-non-breaking-match"]
~default:false ~doc ~section
(fun conf x -> {conf with disambiguate_non_breaking_match= x})
(fun conf -> conf.disambiguate_non_breaking_match)
let doc_comments =
let doc = "Doc comments position." in
let names = ["doc-comments"] in
let all =
[ ( "after-when-possible"
, `After_when_possible
, "$(b,after-when-possible) puts doc comments after the \
corresponding code. This option has no effect on variant \
declarations because that would change their meaning and on \
structures, signatures and objects for readability." )
; ( "before-except-val"
, `Before_except_val
, "$(b,before-except-val) puts doc comments before the \
corresponding code, but puts doc comments of $(b,val) and \
$(b,external) declarations after the corresponding declarations."
)
; ( "before"
, `Before
, "$(b,before) puts comments before the corresponding code." ) ]
in
C.choice ~names ~all ~doc ~section
~removed_values:
[ C.removed_value ~name:"after" ~version:"0.14.2"
~msg:
"This value has been renamed `after-when-possible` to take \
into account the technical limitations of ocamlformat, the \
behavior is unchanged." ]
(fun conf x -> {conf with doc_comments= x})
(fun conf -> conf.doc_comments)
let doc_comments_padding =
let docv = "PADDING" in
let doc =
"Add $(docv) spaces before doc comments in type declarations."
in
let names = ["doc-comments-padding"] in
C.any Arg.int ~names ~default:2 ~doc ~docv ~section
(fun conf x -> {conf with doc_comments_padding= x})
(fun conf -> conf.doc_comments_padding)
let doc_comments_tag_only =
let doc = "Position of doc comments with only tags." in
let names = ["doc-comments-tag-only"] in
let all =
[ ("default", `Default, "$(b,default) means no special treatment.")
; ("fit", `Fit, "$(b,fit) puts doc comments on the same line.") ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with doc_comments_tag_only= x})
(fun conf -> conf.doc_comments_tag_only)
let ( (* doc_comments_val *) ) =
let names = ["doc-comments-val"] in
let version = "0.16.0" in
let msg =
"If you are using `doc-comments-val=before` in combination with \
`doc-comments=before` then only `doc-comments=before` is now \
required to achive the same behavior. If you are using \
`doc-comments-val=before` in combination with `doc-comments=after` \
this behavior is not available anymore. If you are using \
`doc-comments-val=after` in combination with `doc-comments=before` \
please now use `doc-comments=before-except-val`. If you are using \
`doc-comments-val=after` in combination with `doc-comments=after` \
then only `doc-comments=after-when-possible` is now required to \
achieve the same behavior. If you are using `doc-comments-val=unset` \
the same behavior can now be achieved by setting `doc-comments` \
only."
in
C.removed_option ~names ~version ~msg
let dock_collection_brackets =
let doc =
"Dock the brackets of lists, arrays and records, so that when the \
collection does not fit on a single line the brackets are opened on \
the preceding line and closed on the following line."
in
let names = ["dock-collection-brackets"] in
C.flag ~default:true ~names ~doc ~section
(fun conf x -> {conf with dock_collection_brackets= x})
(fun conf -> conf.dock_collection_brackets)
let concrete_syntax_preserved_msg =
"Concrete syntax will now always be preserved."
let ( (* escape_chars *) ) =
let names = ["escape-chars"] in
let version = "0.16.0" in
let msg = concrete_syntax_preserved_msg in
C.removed_option ~names ~version ~msg
let ( (* escape_strings *) ) =
let names = ["escape-strings"] in
let version = "0.16.0" in
let msg = concrete_syntax_preserved_msg in
C.removed_option ~names ~version ~msg
let exp_grouping =
let doc = "Style of expression grouping." in
let names = ["exp-grouping"] in
let all =
[ ( "parens"
, `Parens
, "$(b,parens) groups expressions using parentheses." )
; ( "preserve"
, `Preserve
, "$(b,preserve) preserves the original grouping syntax \
(parentheses or $(i,begin)/$(i,end))." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with exp_grouping= x})
(fun conf -> conf.exp_grouping)
let extension_indent =
let docv = "COLS" in
let doc =
"Indentation of items inside extension nodes ($(docv) columns)."
in
let names = ["extension-indent"] in
C.any Arg.int ~names ~default:2 ~doc ~docv ~section
(fun conf x -> {conf with extension_indent= x})
(fun conf -> conf.extension_indent)
let ( (* extension_sugar *) ) =
let names = ["extension-sugar"] in
let version = "0.17.0" in
let msg = concrete_syntax_preserved_msg in
C.removed_option ~names ~version ~msg
let field_space =
let doc =
"Whether or not to use a space between a field name and the rhs. This \
option affects records and objects."
in
let names = ["field-space"] in
let all =
[ ("loose", `Loose, "$(b,loose) does.")
; ( "tight"
, `Tight
, "$(b,tight) does not use a space between a field name and the \
punctuation symbol (`:` or `=`)." )
; ( "tight-decl"
, `Tight_decl
, "$(b,tight-decl) is $(b,tight) for declarations and $(b,loose) \
for instantiations." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with field_space= x})
(fun conf -> conf.field_space)
let function_indent =
let docv = "COLS" in
let doc = "Indentation of function cases ($(docv) columns)." in
let names = ["function-indent"] in
C.any Arg.int ~names ~default:2 ~doc ~docv ~section
(fun conf x -> {conf with function_indent= x})
(fun conf -> conf.function_indent)
let function_indent_nested =
let doc =
"Whether the $(b,function-indent) parameter should be applied even \
when in a sub-block."
in
let names = ["function-indent-nested"] in
let all =
[ ( "never"
, `Never
, "$(b,never) only applies $(b,function-indent) if the function \
block starts a line." )
; ("always", `Always, "$(b,always) always apply $(b,function-indent).")
; ( "auto"
, `Auto
, "$(b,auto) applies $(b,function-indent) when seen fit." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with function_indent_nested= x})
(fun conf -> conf.function_indent_nested)
let if_then_else =
let doc = "If-then-else formatting." in
let names = ["if-then-else"] in
let all =
[ ( "compact"
, `Compact
, "$(b,compact) tries to format an if-then-else expression on a \
single line." )
; ( "fit-or-vertical"
, `Fit_or_vertical
, "$(b,fit-or-vertical) vertically breaks branches if they do not \
fit on a single line." )
; ( "keyword-first"
, `Keyword_first
, "$(b,keyword-first) formats if-then-else expressions such that \
the if-then-else keywords are the first on the line." )
; ( "k-r"
, `K_R
, "$(b,k-r) formats if-then-else expressions with parentheses that \
match the K&R style." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with if_then_else= x})
(fun conf -> conf.if_then_else)
let indent_after_in =
let docv = "COLS" in
let doc =
"Indentation ($(docv) columns) after `let ... in`, unless followed by \
another `let`."
in
let names = ["indent-after-in"] in
C.any Arg.int ~names ~default:0 ~doc ~docv ~section ~allow_inline:false
(fun conf x -> {conf with indent_after_in= x})
(fun conf -> conf.indent_after_in)
let indicate_multiline_delimiters =
let doc =
"How to indicate that two matching delimiters live on different lines."
in
let names = ["indicate-multiline-delimiters"] in
let all =
[ ( "no"
, `No
, "$(b, no) doesn't do anything special to indicate the closing \
delimiter." )
; ( "space"
, `Space
, "$(b,space) prints a space inside the delimiter to indicate the \
matching one is on a different line." )
; ( "closing-on-separate-line"
, `Closing_on_separate_line
, "$(b, closing-on-separate-line) makes sure that the closing \
delimiter is on its own line." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with indicate_multiline_delimiters= x})
(fun conf -> conf.indicate_multiline_delimiters)
let indicate_nested_or_patterns =
let doc =
"Control whether or not to indicate nested or-pattern using \
indentation."
in
let names = ["indicate-nested-or-patterns"] in
let all =
[ ( "unsafe-no"
, `Unsafe_no
, "$(b,unsafe-no) does not indicate nested or-patterns. Warning: \
this can produce confusing code where a short body of a match \
case is visually hidden by surrounding long patterns, leading to \
misassociation between patterns and body expressions." )
; ( "space"
, `Space
, "$(b,space) starts lines of nested or-patterns with \" |\" rather \
than \"| \"." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with indicate_nested_or_patterns= x})
(fun conf -> conf.indicate_nested_or_patterns)
let infix_precedence =
let doc =
"Use indentation or also discretionary parentheses to explicitly \
disambiguate precedences of infix operators."
in
let names = ["infix-precedence"] in
let all =
[ ( "indent"
, `Indent
, "$(b,indent) uses indentation to explicitly disambiguate \
precedences of infix operators." )
; ( "parens"
, `Parens
, "$(b,parens) uses parentheses to explicitly disambiguate \
precedences of infix operators." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with infix_precedence= x})
(fun conf -> conf.infix_precedence)
let leading_nested_match_parens =
let doc = "Nested match parens formatting." in
let names = ["leading-nested-match-parens"] in
C.flag ~default:false ~names ~doc ~section ~allow_inline:false
(fun conf x -> {conf with leading_nested_match_parens= x})
(fun conf -> conf.leading_nested_match_parens)
let let_and =
let doc = "Style of let_and." in
let names = ["let-and"] in
let all =
[ ( "compact"
, `Compact
, "$(b,compact) will try to format `let p = e and p = e` in a \
single line." )
; ("sparse", `Sparse, "$(b,sparse) will always break between them.") ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with let_and= x})
(fun conf -> conf.let_and)
let let_binding_indent =
let docv = "COLS" in
let doc =
"Indentation of let binding expressions ($(docv) columns) if they do \
not fit on a single line."
in
let names = ["let-binding-indent"] in
C.any Arg.int ~names ~default:2 ~doc ~docv ~section ~allow_inline:false
(fun conf x -> {conf with let_binding_indent= x})
(fun conf -> conf.let_binding_indent)
let let_binding_spacing =
let doc = "Spacing between let binding." in
let names = ["let-binding-spacing"] in
let all =
[ ( "compact"
, `Compact
, "$(b,compact) spacing separates adjacent let bindings in a module \
according to module-item-spacing." )
; ( "sparse"
, `Sparse
, "$(b,sparse) places two open lines between a multi-line \
module-level let binding and the next." )
; ( "double-semicolon"
, `Double_semicolon
, "$(b,double-semicolon) places double semicolons and an open line \
between a multi-line module-level let binding and the next." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with let_binding_spacing= x})
(fun conf -> conf.let_binding_spacing)
let let_module =
let doc = "Module binding formatting." in
let all =
[ ( "compact"
, `Compact
, "$(b,compact) does not break a line after the $(i,let module ... \
=) and before the $(i,in) if the module declaration does not fit \
on a single line." )
; ( "sparse"
, `Sparse
, "$(b,sparse) breaks a line after $(i,let module ... =) and before \
the $(i,in) if the module declaration does not fit on a single \
line." ) ]
in
C.choice ~names:["let-module"] ~all ~doc ~section
(fun conf x -> {conf with let_module= x})
(fun conf -> conf.let_module)
let ( (* let_open *) ) =
let names = ["let-open"] in
let version = "0.17.0" in
let msg = concrete_syntax_preserved_msg in
C.removed_option ~names ~version ~msg
let margin =
let docv = "COLS" in
let doc = "Format code to fit within $(docv) columns." in
C.any Arg.int ~names:["m"; "margin"] ~default:80 ~doc ~docv ~section
~allow_inline:false
(fun conf x -> {conf with margin= x})
(fun conf -> conf.margin)
let match_indent =
let docv = "COLS" in
let doc = "Indentation of match/try cases ($(docv) columns)." in
let names = ["match-indent"] in
C.any Arg.int ~names ~default:0 ~doc ~docv ~section
(fun conf x -> {conf with match_indent= x})
(fun conf -> conf.match_indent)
let match_indent_nested =
let doc =
"Whether the $(b,match-indent) parameter should be applied even when \
in a sub-block."
in
let names = ["match-indent-nested"] in
let all =
[ ( "never"
, `Never
, "$(b,never) only applies $(b,match-indent) if the match block \
starts a line." )
; ("always", `Always, "$(b,always) always apply $(b,match-indent).")
; ("auto", `Auto, "$(b,auto) applies $(b,match-indent) when seen fit.")
]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with match_indent_nested= x})
(fun conf -> conf.match_indent_nested)
let default_max_indent =
(* Creating a fresh formatter in case the value of max-indent has been
changed for stdout. *)
let fs = Format.formatter_of_buffer (Buffer.create 0) in
Int.to_string (Format.pp_get_max_indent fs ())
let max_indent =
let docv = "COLS" in
let doc =
"Maximum offset ($(docv) columns) added to a new line in addition to \
the offset of the previous line."
in
C.any
Arg.(some ~none:default_max_indent int)
~names:["max-indent"] ~doc ~docv ~section ~default:None
~allow_inline:false
(fun conf x -> {conf with max_indent= x})
(fun conf -> conf.max_indent)
let module_item_spacing =
let doc = "Spacing between items of structures and signatures." in
let names = ["module-item-spacing"] in
let all =
[ ( "sparse"
, `Sparse
, "$(b,sparse) will always break a line between two items." )
; ( "preserve"
, `Preserve
, "$(b,preserve) will not leave open lines between one-liners of \
similar sorts unless there is an open line in the input." )
; ( "compact"
, `Compact
, "$(b,compact) will not leave open lines between one-liners of \
similar sorts." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with module_item_spacing= x})
(fun conf -> conf.module_item_spacing)
let nested_match =
let doc =
"Style of a pattern-matching nested in the last case of another \
pattern-matching."
in
let names = ["nested-match"] in
let all =
[ ( "wrap"
, `Wrap
, "$(b,wrap) wraps the nested pattern-matching with parentheses and \
adds indentation." )
; ( "align"
, `Align
, "$(b,align) vertically aligns the nested pattern-matching under \
the encompassing pattern-matching." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with nested_match= x})
(fun conf -> conf.nested_match)
let ocp_indent_compat =
let doc =
"Attempt to generate output which does not change (much) when \
post-processing with ocp-indent."
in
let names = ["ocp-indent-compat"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with ocp_indent_compat= x})
(fun conf -> conf.ocp_indent_compat)
let parens_ite =
let doc =
"Uses parentheses around if-then-else branches that spread across \
multiple lines."
in
let names = ["parens-ite"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with parens_ite= x})
(fun conf -> conf.parens_ite)
let parens_tuple =
let doc = "Parens tuple expressions." in
let names = ["parens-tuple"] in
let all =
[ ( "always"
, `Always
, "$(b,always) always uses parentheses around tuples." )
; ( "multi-line-only"
, `Multi_line_only
, "$(b,multi-line-only) mode will try to skip parens for \
single-line tuples." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with parens_tuple= x})
(fun conf -> conf.parens_tuple)
let parens_tuple_patterns =
let doc = "Parens tuple patterns." in
let names = ["parens-tuple-patterns"] in
let all =
[ ( "multi-line-only"
, `Multi_line_only
, "$(b,multi-line-only) mode will try to skip parens for \
single-line tuple patterns." )
; ( "always"
, `Always
, "$(b,always) always uses parentheses around tuples patterns." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with parens_tuple_patterns= x})
(fun conf -> conf.parens_tuple_patterns)
let parse_docstrings =
let doc = "Parse and format docstrings." in
let names = ["parse-docstrings"] in
C.flag ~default:false ~names ~doc ~section
(fun conf x -> {conf with parse_docstrings= x})
(fun conf -> conf.parse_docstrings)
let sequence_blank_line =
let doc = "Blank line between expressions of a sequence." in
let names = ["sequence-blank-line"] in
let all =
[ ( "preserve-one"
, `Preserve_one
, "$(b,preserve) will keep a blank line between two expressions of \
a sequence if the input contains at least one." )
; ( "compact"
, `Compact
, "$(b,compact) will not keep any blank line between expressions of \
a sequence." ) ]
in
C.choice ~names ~all ~doc ~section
(fun conf x -> {conf with sequence_blank_line= x})