So what I ended up doing is the strategy described earlier, it uses the same logic as what's being used for "newline" presses. It applies this to adjust the indentation for the first two lines, computes the "movement" of the second line, and moves all subsequent lines relative (i.e indent or outdents by the same distance as the 2nd line was moved).
There are some weaknesses in the implementation that I know of.
Mainly the newline strategy is not 100% reliable, so when that fails it will move the code by the wrong distance.
Also the smart paste currently is only implemented to work when pasting on empty lines. If that turns out to be an issue I could work on generalizing it.
There may be other potential limitations / bugs that I don't know about.
I'd be interested to hear any complaints, both about the gravity of the "known issues" or other unexpected bugs. These are particularly nice if they come with specific examples that I can try to fix. (e.g. your posted example in this issue became one of my first test cases
A patch is attached. Unfortunately, it looks like our build script that publishes snapshot builds has not been working ever since codehaus has reconfigured the bamboo servers. So it may be some time before a snapshot build is actually available.
I'll keep this issue open and post a message when I've seen a successful build/snapshot go through, so you know when there's actually something that can be tried out.