I'd like to run indent on each .c and .h file I open in vim. I've looked at setting equalprg, but I'd rather have it done for me when I open the buffer, so I tried:
autocmd BufReadPost *.[ch] '[,']!indent
This works fine if the file has no syntax errors, but spews error messages from indent into the file if I'm missing a closing brace, say. I haven't done anything with plugins before. Am I better off writing an ftplugin? I don't mind silent failure on errors, but the file should be left pristine in that case. Any hints greatly appreciated.