Search code examples
emacsalignment

Does emacs have a way to align the '='s inside a C++ enum


I've frequently had code blocks that look like this:

enum class MyEnum {
    first = 1,
    second_really_long_line = 2,
    third = 3
};

That I want to look like this:

enum class MyEnum {
    first                   = 1,
    second_really_long_line = 2,
    third                   = 3
};

Is there a way, in emacs, that I can get the = all in the same column for the body of the enum?


Solution

  • Select the entire block and run M-x align.

    Emacs' C modes arrange for align to do useful things in quite a few situations, so it is often worth trying if you have an alignment problem.