Allman indentation in Emacs with C++ in-class-defined member-functions

52 views Asked by At

I want Allman-indentation. Thus I tried to set c-default-style to each of these: stroustrup, bsd, linux. None of these address the behavior that I see in the below code snippet.

NOTE: This question is only relevant for in-class-definition of member functions, which is why other answers on Emacs indentation do not answer this question. As you can see in the snippet, out-of-class definitions are just how I want them to be. Further notice: When I made the code examples inside Emacs and pasted them here, I noticed that 2.) was formatted like 1.) and I had to adjust indent inside the markdown editor of stackoverflow to match what I see inside Emacs. What I'm getting at here is that maybe it might be a displaying issue of Emacs rather than an actual indentation issue? Emacs version is 29.1.

struct Foo
{
    // 1.)
    void bar()
    {
        std::cout << "\n" << std::endl;
    }

    // 2.)
    void printFoo()
        {
            std::cout << "foo" << std::endl;
        }

    // 3.)
    void printFoo() const {
        std::cout << "const foo" << std::endl;
    }

    void printFooNum(int foonum);
};

// 4.)
void Foo::printFooNum(int foonum)
{
    std::cout << "foonum: " << foonum << std::endl;
}

1.) Is the indentation style that I'm trying to achieve.
2.) Is what I get per default with any of the indentation styles that I tried (see above).
3.) Is what I get when I leave the brace on the last line, this could be acceptable but it's not Allman (and thus not what I want).
4.) Is what I get per default (and what I want) but it's an out-of-class definition. I also want this to work for in-class definition.

I'm also giving you the relevant section of my init.el:

(setq c-default-style '((c++-mode . "stroustrup")
                        (c-mode   . "stroustrup"))
      c-basic-offset 4)
(setq evil-shift-width 4)
0

There are 0 answers