Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.