Thanks.
Attached is another patch.
It handles quotes (with guess work that is often, but not always, close enough) and attempts to act more intelligently during brace completion. I have also now separated it into a function, and called the function from the SmartIndent plugins that have not yet implemented their own brace completion.
I still want to write some specialized functions; the fall-back function attempts to be generalized, so it misses many language specifics (for example triple quoted python strings).