vim-codefmt icon indicating copy to clipboard operation
vim-codefmt copied to clipboard

Add mechanism for chaining formatters

Open dbarnett opened this issue 10 years ago • 3 comments

For some types of files you might want to run more than one formatter, for instance sort C++ includes (which clang-format doesn't handle) and then format with clang-format. Could codefmt support configuring a list of formatters instead of a single formatter? E.g.

AutoFormatBuffer sortincludes,clang-format
let b:codefmt_formatter = ['sortincludes', 'clang-format']

dbarnett avatar Jul 06 '15 22:07 dbarnett

Our hacky solution when this came up (for imports+formatting in java) was to define a little one-off formatter with its own formatter name that delegated and called formatter A then formatter B.

As noted in #178, you can't just invoke :AutoFormatBuffer twice and its docs don't explicitly explain it'll replace any previous autoformatting each time you invoke it.

dbarnett avatar Apr 15 '21 15:04 dbarnett

I think my hacky solution is a bit easier than what you describe, since I only needed to add a function to do the delegation, instead of a whole formatter.

TamaMcGlinn avatar Apr 15 '21 18:04 TamaMcGlinn

Yes, that's probably close to what I would've done as a one-off workaround. For our purposes on the java thing, we were solving a common issue and couldn't plop arbitrary autocmds into everyone's vimrc.

dbarnett avatar Apr 15 '21 19:04 dbarnett