As pointed out by others, you can mark the entire buffer C-x h, and then indent the area withC-M-\
You can also put something along these lines in a file .emacs:
(defun my-indent-buffer()
(interactive)
(save-excursion
(indent-region (point-min) (point-max))))
(global-set-key "\C-cib" 'my-indent-buffer)
It makes sense to remember your point.
source
share