I have a problem similar that for which nnoremap was conceived, but for the BufWrite aucmd.
I have a code formatter which isn't very well-behaved. Gnatpp demands to read a file directly rather than be fed stdin and output stdout as is the norm for code formatters.
First I tried this:
autocmd BufWrite *.ad[sb] Autoformat
But the problem is that, while 'Autoformat' itself works fine, it reads the file contents before writing. Hence, it makes it impossible to change any Ada source files anymore! How can I prepend an operation to this to 'write but without executing this autocmd' ?
As suggested, I have also tried BufWritePost instead, which allows one to change the file, but not I need to do :w
twice - the first time, the buffer is changed after writing the file, and the second write will write the formatting changes.
autocmd BufWritePost *.ad[sb] Autoformat
fails on the other side; it reads the file I modified by hand fine, but it fails to then write again afterwards (without triggering itself):w
, without triggering itself. Hence, that is the question.:w
triggers the autocommand and Autowrite is also doing:w
which triggers the autocommand again? (IOW, nothing is actually calling itself...it's just a circular series of events.)