• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

auto-indenting with emacs

toughwimp11

Senior member
I have some c source and header files that I want to automatically intend in emacs and I was wondering if there was a way to do a whole file at a time. I can go line by line and press tab but that takes too much time, is there a way to just apply it to the whole file?
 
I'm a ViM guy, not an emacs guy, so in ViM I'd just do "gg=G". 🙂

But as I recall, Emacs is supposed to provide a way to do easy compilation. As an alternative to dinkumthinkum's suggestion (which is probably better), if you could pass your source to indent instead of gcc, I imagine that would do it.
 
You could pass the region to a shell command like indent using the command M-| but indent may be using a different style than your emacs settings. But this is essentially equivalent to vim's gg=g or :%!indent commands.

You could also go nuts and use dired (C-x d) to open a directory then mark (m) the files in question and use the shell command key (!) to run indent on the marked files.
 
Back
Top