Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the following in my .emacs for my c code formatting:

(setq c-default-style "linux" c-basic-offset 4)

And I try to format my region by doing: M-x indent-region

But my code does not get formatted.

int    f1(int a, int b,    int c);
int f2();

f1 and f2 does not get aligned and there are extra space between 'int b' and int c', emacs does not format that for me

And struct mystruct{ int field1; int field2; int field3; }

none of the field are aligned after I do 'indent-region'

Can you please tell me how to get emacs c code formatting to work?

share|improve this question
up vote 2 down vote accepted

indent-region only indents. It doesn't do full formatting or splitting lines. If you want more formatting options, try using something like astyle.

share|improve this answer

That emacs formatting applies to only the initial tab stops. To pretty-print your code in other positions you'll need a different utility.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .