@@ -18,6 +18,7 @@ helpfiles in the `doc/` directory. The helpfiles are also available via
1818* Go (gofmt)
1919* [ GN] ( https://www.chromium.org/developers/gn-build-configuration ) (gn)
2020* HTML (js-beautify)
21+ * Java (google-java-format or clang-format)
2122* JavaScript (clang-format)
2223* JSON (js-beautify)
2324* Proto (clang-format)
@@ -62,6 +63,7 @@ call vundle#end()
6263call glaive#Install()
6364" Optional: Enable codefmt's default mappings on the <Leader>= prefix.
6465Glaive codefmt plugin[mappings]
66+ Glaive codefmt google_java_executable="java -jar /path/to/google-java-format-VERSION-all-deps.jar"
6567```
6668
6769Make sure you have updated maktaba recently. Codefmt depends upon maktaba
@@ -80,13 +82,21 @@ augroup autoformat_settings
8082 autocmd FileType go AutoFormatBuffer gofmt
8183 autocmd FileType gn AutoFormatBuffer gn
8284 autocmd FileType html,css,json AutoFormatBuffer js-beautify
85+ autocmd FileType java AutoFormatBuffer google-java-format
8386 autocmd FileType python AutoFormatBuffer yapf
8487 " Alternative: autocmd FileType python AutoFormatBuffer autopep8
8588augroup END
8689```
8790
91+ # Configuring formatters
8892
89- # Installing and configuring formatters
93+ Most formatters have some options available that can be configured via
94+ [ Glaive] ( https://www.github.com/google/vim-glaive )
95+ You can get a quick view of all codefmt flags by executing ` :Glaive codefmt ` , or
96+ start typing flag names and use tab completion. See ` :help Glaive ` for usage
97+ details.
98+
99+ # Installing formatters
90100
91101Codefmt defines several built-in formatters. The easiest way to see the list of
92102available formatters is via tab completion: Type ` :FormatCode <TAB> ` in vim.
@@ -99,31 +109,28 @@ trigger formatters via key mappings and/or autocommand hooks. See
99109vroom/main.vroom to learn more about formatting features, and see
100110vroom/FORMATTER-NAME.vroom to learn more about usage for individual formatters.
101111
102- Most formatters have some options available that can be configured via Glaive.
103- You can get a quick view of all codefmt flags by executing ` :Glaive codefmt ` , or
104- start typing flag names and use tab completion. See ` :help Glaive ` for usage
105- details.
106-
107112## Creating a New Formatter
108113
109114Assume a filetype ` myft ` and a formatter called ` MyFormatter ` . Our detailed
110115guide to creating a formatter [ lives
111116here] ( https://github.com/google/vim-codefmt/wiki/Formatter-Integration-Guide ) .
112117
113- * Create an issue for your new formatter and discuss! Once there's consensus,
114- continue onward.
118+ * Create an issue for your new formatter and discuss!
115119
116120* Create a new file in ` autoload/codefmt/myformatter.vim ` See
117121 `autoload/codefmt/buildifier.vim for an example. This is where all the
118122 logic for formatting goes.
119123
120- * Register the formatter with:
124+ * Register the formatter in
125+ [ plugin/register.vim] ( plugin/register.vim )
126+ with:
121127
122128 ``` vim
123129 call s:registry.AddExtension(codefmt#myformatter#GetFormatter())
124130 ```
125131
126- * Create a flag in instant/flags.vim
132+ * Create a flag in
133+ [instant/flags.vim](instant/flags.vim)
127134
128135 ```vim
129136 ""
@@ -134,6 +141,8 @@ here](https://github.com/google/vim-codefmt/wiki/Formatter-Integration-Guide).
134141* Create a [vroom](https://github.com/google/vim-vroom) test named
135142 `vroom/myformatter.vroom` to ensure your formatter works properly.
136143
144+ * Update the README.md to mention your new filetype!
145+
137146That's it! Of course, the complicated step is in the details of
138147`myformatter.vim`.
139148
0 commit comments