rhysd/vim-clang-format

Detect if file is formattable

GiuseppeCesarano opened this issue · 2 comments

Sometimes when i write cmake files muscle memory kicks in and i press the shortcut to call :ClangFormat, resulting in my code hardly messed up, nothing that the undo command can't resolve. Is there any way i can prevent :ClangFormat to run if the file isn't supported?

For example Prettier doesn't create it's method if the file isn't supported. There is something i can check to evaluate the file support?

Sharing my spontaneous thought: personally I have the same trait as you (wanting to format everything), but I make use of gd instead, via g:clang_format#auto_formatexpr which makes gd file-type-aware via autocmd. I guess my reasoning is that this opens up for a more generic way to formatting any file (you could have another formatter for cmake-files).

Would my approach alleviate your concerns?

Yes that actually helped me implement the behavior i wanted, thank you.