Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have several empty inline function definitions in C++ like so:

class C
{
    void foo(){}
    void bar(){}
};

now if I run indent -st -i4 -nut test.cc in order to just fix the indentation I get

class C
{
    void foo ()
    {
    }
    void bar ()
    {
    }
};

But I just want to fix the indentation without moving curly braces around!

How can I achieve that?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Looking at man indent I see using -brf will put braces on the function definition line. If you want it on the if-line as well, you'll need -br.

If your PAGER environment variable is less you can search through man indent with / and the text. So if you do man indent, followed by /braces<ENTER> You'll be able to hop between matches that are informative to you by pressing n repeated.

Edit to make my comment below clearer, this is what I see in man indent

The `-brf´ option formats braces like this:

        int one(void) {
          return 1;
        };

The `-blf´ option formats them like this:

        int one(void)
        {
          return 1;
        };
share|improve this answer
    
-brf will put the closing brace in the next line. What I want is that indent leaves all braces alone... –  steffen Jan 16 '13 at 13:35
    
@steffen the documentation says you're wrong -brf, --braces-on-func-def-line // Put braces on function definition line. –  sigmavirus24 Jan 16 '13 at 14:13
    
that's right, the short explanation is misleading. Scroll down to section DECLARATIONS and find the long explanation. –  steffen Jan 16 '13 at 14:50
    
On all the different variants of linux (and versions of those) I have access to the section you reference has been edited into my original answer. –  sigmavirus24 Jan 17 '13 at 20:56
    
Yep, that's what I found. I would like that indent left the braces alone alltogether but that seems not to be possible. I'll accept your answer anyway because your answer is comprehensive (and you were the only one to bother ;) ) Thanks. –  steffen Jan 19 '13 at 8:41
show 1 more comment

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.