How to format on buffer change?
I have tried to add an hook with after-change-functions but it didn't work.
This feature would need to be added, as currently the logic for change detection will cause a graceful exit/no-op in the case that the buffer has been modified since the last save.
That said... you'd sure want to be careful with this. You would potentially be starting multiple external processes in parallel on every keystroke. It might be more fruitful to set the formatting to happen on an idle timer, so that reformatting would only happen after the user stops typing for a second or two. Also if you formatted on every keystroke, you'd get a lot of spurious errors from formatters detecting invalid (not-yet-valid) syntax, and possibly dumpstering your in-progress line of code.