mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.94k stars 716 forks source link

Format wipes buffer on error with formatcmd #1357

Closed melboyce closed 7 years ago

melboyce commented 7 years ago

As per @casimir 's request, I'm logging this issue here and closing one in @lenormf 's kakoune-extras repo.

The :format command will wipe the buffer if the command specified by the formatcmd setting returns an error instead of a copy of the code. I'm happy to take a crack at a PR against rc/core/formatter.kak if that's the best place to deal with this.

melboyce commented 7 years ago

Note: the last sentence is actually a question. Is it best to work on rc/core/formatter.kak or is there somewhere in the cpp that I need to grok and change?

casimir commented 7 years ago

This is indeed the place to deal with this. If you have questions the best way to get quick answer is on IRC.

mawww commented 7 years ago

Hello, sorry for the delay, this one slipped through. The problem is that the return value from the commands used in the | (or !) normal mode key is not interpretted at all by Kakoune.

Here, we could fix that by either having | not replace the text if the command does not exit successfully, or make it possible to access that command exit status from a %sh{...} shell so that the formatter.kak script could trigger a undo when the status was not 0.

The first solution looks like its going to be refusing to pipe in various legitimate cases. The second seems very specific, so not very elegant.

melboyce commented 7 years ago

All good - I haven't had a chance to work on my Kakoune environment for a while due to work. I'll see how it feels to handle this all in the formatter shell script by using a temp file when I have some time.