-
Notifications
You must be signed in to change notification settings - Fork 114
Formatter Integration Guide
If you have a formatter codefmt doesn't support that you want to integrate with codefmt, you have two choices:
- Implement a codefmt extension plugin for your formatter.
- Add it directly into codefmt.
For robust, publicly available formatters, adding them directly into codefmt is usually fine. See the FAQ for reasons to go with one approach over the other.
TODO: Details
The first step for integrating a new formatter with codefmt directly is always to file a feature request for your formatter at https://github.com/google/vim-codefmt/issues if one hasn't already been filed.
Next, read through :help codefmt
, have a look at the other formatters implemented in autoload/codefmt.vim for inspiration, and get started implementing the formatter API.
TODO: Specifics
Codefmt formatters work better in a lot of corner cases and support several nice features like
- a simple format-on-save mechanism
- range formatting
- motion mappings to format specific code blocks, etc.
The quick and dirty :%!SOMEFORMATTER
approach also won't have any error handling. Once you add error handling and such, the advantages of the quick and dirty approach vs. a codefmt formatter are less obvious.
Why would I want to implement a separate extension plugin instead of adding the formatter into codefmt directly?
The main reasons are if the formatter isn't ready for wide adoption, if it has dependencies that are hard to install, or if it's a special-purpose/proprietary formatter.