-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathocamlformat.vroom
More file actions
100 lines (79 loc) · 2.24 KB
/
ocamlformat.vroom
File metadata and controls
100 lines (79 loc) · 2.24 KB
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
The built-in ocamlformat formatter knows how to format ocaml code.
If you aren't familiar with basic codefmt usage yet, see main.vroom first.
We'll set up codefmt and configure the vroom environment, then jump into some
examples.
:source $VROOMDIR/setupvroom.vim
:let g:repeat_calls = []
:function FakeRepeat(...)<CR>
| call add(g:repeat_calls, a:000)<CR>
:endfunction
:call maktaba#test#Override('repeat#set', 'FakeRepeat')
:call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0)
The ocamlformat formatter expects the ocamlformat executable to be installed on your system.
@clear
% f()
:FormatCode ocamlformat
! ocamlformat .*
$ ;;
$ f ()
;;
f ()
@end
The name or path of the ocamlformat executable can be configured via the
ocamlformat_executable flag if the default of "ocamlformat" doesn't work.
@clear
:Glaive codefmt ocamlformat_executable='myocamlformat'
:FormatCode ocamlformat
! myocamlformat .*
$ ;;
$ f ()
:Glaive codefmt ocamlformat_executable='ocamlformat'
You can format any buffer with ocamlformat specifying the formatter explicitly.
@clear
% let x=5 in<CR>
| let inc x=x+1 in<CR>
| print_endline (string_of_int (inc x))
:FormatCode ocamlformat
! ocamlformat .*
$ ;;
$ let x = 5 in
$ let inc x = x + 1 in
$ print_endline (string_of_int (inc x))
;;
let x = 5 in
let inc x = x + 1 in
print_endline (string_of_int (inc x))
@end
The ocaml filetype will use the ocamlformat formatter by default. The path to the
file being edited is passed to ocamlformat so that it can adjust to whether the
file is an implementation or an interface file.
@clear
% f()
:silent file /foo/bar/test.ml
:set filetype=ocaml
:FormatCode
! ocamlformat - --name /foo/bar/test.ml .*
$ ;;
$ f ()
;;
f ()
@end
It can format specific line ranges of code using :FormatLines.
@clear
% print_string "Hello";;<CR>
|let x=1 in let y=2 in<CR>
|y+2
:2,3FormatLines ocamlformat
! ocamlformat .*
$ ;;
$ let x = 1 in
$ let y = 2 in
$ y + 2
print_string "Hello";;
;;
let x = 1 in
let y = 2 in
y + 2
@end
NOTE: the ocamlformat formatter does not natively support range formatting, so there
are certain limitations like not being able to format misaligned braces.