FormatAction: extract the Writer into an inner class

Just for readability
FormatAction: Respect whitespace settings

Use spaces-for-tabs and editor-tab-width for indentation, and the
document’s newline string as line break.

Implements and closes #998.
Add preference to format on save

Implements and closes #997.