You can extend the KDE Kate editor with JavaScript, and control e.g. the undo buffer.
I would like to call e.g. HTML Tidy from inside such a script, but I cannot find any bindings from inside the JavaScript environment to access the shell, the web, the menus or anything else that would make it possible to reach out. It seems to be a completely self contained world, where everything needs to be coded from scratch.
I have made HTML Tidy work as a plain command line script inside Kate, but alas, your undo buffers get destroyed.