Even faster, use C-x h to highlight everything, then C-M-\ to re-indent it. Also, C-j normally does a newline-and-indent type function (for most modes; not Emacs Lisp Interaction though). If you want to do a sort of auto-indentation for certain modes, you can bind the RETURN key to do indentation like so:
Code:
;; My new binding to use for <RET> in some modes.
(defmacro taylor-return-key nil
'(lambda nil (interactive) (progn (indent-according-to-mode) (newline-and-indent))))
;;
;; Rebind <RET> key to do automatic indentation in certain modes.
;;
(mapcar
(lambda (mode)
(let ((mode-hook (intern (concat (symbol-name mode) "-hook"))))
(add-hook mode-hook (lambda nil (local-set-key (kbd "RET") (taylor-return-key))))))
'(ada-mode c-mode c++-mode cperl-mode emacs-lisp-mode java-mode html-mode
lisp-mode php-mode ruby-mode sgml-mode sh-mode tuareg-mode))
Just list whatever modes you want to apply it for in that last list with all the mode names in it. This is what I use for almost everything. When you hit RETURN, it reindents the current line, moves you down to the next line, and auto-indents there. Very useful.