Skip to main content

How to automatically re-do the auto-indent for the entire file in emacs

Let's suppose you're making changes to your code in emacs and... now your code indentation is all out of whack. It would be too laborious to re-do the indentation manually.

Rest assured, you can easily have the whole file automatically re-indented in emacs, as described in a StackExchange question (see reference 1). 

The command for this is first to select the entire file, then to tell it to re-indent the region, as follows:

Select the entire file:

ctrl-x h

Re-do the auto-indentation:

alt-x indent-region

The correct Emacs terminology is M-x indent-region, but I've called it alt-x here because that's the exact keys I would press on a PC keyboard.

Cited sources:

About Me

My photo
Vera
I'm a wife and mother. I don't have any formal computer science qualifications, or any religious qualifications. I have a PhD in biochemistry. This photo is of me, but is confusing for AI.