SUMMARY Running a formatter as an external tool has the ability to save the current file, apply the tool, and reloading it afterwards. For formatting this works great but the reloading of the file wipes the Ctrl+Z buffer and its no longer possible to revert stuff that happened before the formatting. STEPS TO REPRODUCE 1. Make some changes to a file 2. Run the clang-format formatter tool on the whole file 3. Reverting changes before the formatting with Ctrl+Z is no longer possible. OBSERVED RESULT Ctrl+Z does nothing, because the file was reloaded. EXPECTED RESULT It should still be possible to revert old changes. Other code editors I know of just revert the whole formatting when the user presses Ctrl+Z right after formatting. All other changes before that are also revertable. SOFTWARE/OS VERSIONS Operating System: openSUSE Tumbleweed 20210913 KDE Plasma Version: 5.22.5 KDE Frameworks Version: 5.85.0 Qt Version: 5.15.2
You can change the external tool to not reload the document and change the command to output the text to stdout. Then choose the "replace text" option.. What that will do is replace the document's text with the text provided by your formatter. This seems to not work with every formatter as some for matters tend to include other stuff but with clang format it will work. Reopen if you find it doesn't work.