We often have to work with code written by other people, and though it would be nice if people did their indentation on their own, many people just aren’t bothered. Life is too short to waste time re-indenting somebody’s badly written code. Let Emacs come to your rescue.
Select the offending piece of code, and run the command
Came across something a bit more useful. Here is a function to re-indent the entire buffer (without having to select it first)
(defun iwb ()
“indent whole buffer”
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
Just add it to your .emacs file. Next time you open a buffer, execute M-x iwb, and get properly indented code.