Try electric indent mode.