auto-indenting with emacs

toughwimp11

Senior member
May 8, 2005
415
0
76
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?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,838
4,817
75
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.
 

dinkumthinkum

Senior member
Jul 3, 2008
203
0
0
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.