@@ -30,3 +30,64 @@ format all files from your codebase:
30
30
``` shell
31
31
opam exec -- dune fmt
32
32
```
33
+
34
+ ## Using Topiary
35
+
36
+ [ Topiary] ( https://topiary.tweag.io ) is a Tree-sitter-based code formatter
37
+ supporting multiple languages, including OCaml & OCamllex. It can be invoked
38
+ with
39
+
40
+ <!-- markdownlint-disable commands-show-output -->
41
+ ``` shell-session
42
+ $ topiary format source.ml
43
+ ```
44
+ <!-- markdownlint-restore -->
45
+
46
+ Topiary does not require an empty configuration file to operate & has its own
47
+ set of defaults, however, it can be
48
+ [ configured] ( https://topiary.tweag.io/book/cli/configuration.html ) .
49
+
50
+ ### Example configuration setup
51
+
52
+ This example configuration will override the default configuration to use 1 tab
53
+ character for indentation by creating a ` .topiary.ncl ` Nickel configuration
54
+ file.
55
+
56
+ <!-- markdownlint-disable commands-show-output -->
57
+ ``` shell-session
58
+ $ touch .topiary.ncl
59
+ $ $EDITOR .topiary.ncl
60
+ ```
61
+ <!-- markdownlint-restore -->
62
+
63
+ <!-- markdownlint-disable no-hard-tabs -->
64
+ ``` nickel
65
+ {
66
+ languages = {
67
+ nickel.indent | priority 1 = "\t",
68
+ ocaml.indent | priority 1 = "\t",
69
+ ocaml_interface.indent | priority 1 = "\t",
70
+ ocamllex.indent | priority 1 = "\t",
71
+ },
72
+ }
73
+ ```
74
+ <!-- markdownlint-restore -->
75
+
76
+ Then this file needs to be exported to the environment such as `export
77
+ TOPIARY_CONFIG_FILE=".topiary.ncl"` in Bash/ZSH or ` set -x TOPIARY_CONFIG_FILE
78
+ ".topiary.ncl"` in Fish.
79
+
80
+ TIP: If using Direnv, the environment variable can also be added to the user’s
81
+ personal ` .envrc ` so it is exported on switching to the project directory by
82
+ appending with ` echo 'export TOPIARY_CONFIG_FILE=".topiary.ncl"' >> .envrc ` .
83
+
84
+ Afterwards, ` --merge-configuration ` will always merge in the example
85
+ configuration. Invoke Topiary’s formatting with
86
+
87
+ <!-- markdownlint-disable commands-show-output -->
88
+ ``` shell-session
89
+ $ topiary format --merge-configuration source.ml
90
+ ```
91
+ <!-- markdownlint-restore -->
92
+
93
+ and/or configure your editor to run this command on saving the file.
0 commit comments