vy32
vy32

Reputation: 29727

How can I fix emacs indentation of C++ initializers?

Emacs doesn't properly indent C++ class definitions for allocators that have initializers with colons in them. I think that this is because lines with colons are left-indented in many cases.

I would like to fix this.

Here is an example of what I am talking about.

EMACS indents the code like this:

class demo {
    int x;
    demo(){
    }
 demo(int y):x(y){
    };
};

But it should really indent it like this:

class demo {
    int x;
    demo(){
    }
    demo(int y):x(y){
    };
};

Is there a way to fix this behavior? Presumably we need some elisp...

Thanks!

Upvotes: 3

Views: 822

Answers (1)

Philipp
Philipp

Reputation: 49850

Emacs (at least version 23) doesn't do this in C mode, but it does in C++ mode since in C the part before the colon can only be a label. Make sure you're in C++ mode (M-x c++-mode).

Upvotes: 5

Related Questions