Updated version - this one works, partially.  It actually makes a pretty good guess at what level of indentation to use as the maximum.  Doesn't work for continuation lines yet, but that's going to be the really hard one.