Use electric-indent-mode instead of doign it.