Clang-format ideas

Hi there,

We've recently started using clang-format, and have run into some
places where our coding standard won't fit.

Would you accept patches for the following ideas?

1) As far as I can tell the indentation for continuation lines is
always 4. Is there a strong reason, or could we add a style option for
it?
2) We have a slightly unusual standard for namespace declarations,
where we nest them on one line, e.g.

  namespace foo { namespace bar { namespace baz {

  class Quux {};

  }}}

It looks like this is related to both BreakBeforeBraces and
NamespaceIndentation, but probably a third option...
NamespaceDeclsOnOneLine?

I'd love to put some time into this if it seems like good ideas.

Thanks,
- Kim

Hi Kim,

Daneil Jasper (CC’d) has done a lot of changes on the clang-format tool, he might be of some help.

Hi Kim,

Daneil Jasper (CC'd) has done a lot of changes on the clang-format tool,
he might be of some help.

1) As far as I can tell the indentation for continuation lines is
always 4. Is there a strong reason, or could we add a style option for
it?

I don't see why it should be a fixed option. Looks like no one bothered
changing. :wink:

I've recently encountered one project where the coding standard requires
that continuation lines be indented by 1 space, and I found this to be an
issue with clang-format's formatting as well; it would be great to make
this configurable :slight_smile:

-- Sean Silva

Thanks, all!

1) As far as I can tell the indentation for continuation lines is
always 4. Is there a strong reason, or could we add a style option for
it?

I don't see why it should be a fixed option. Looks like no one bothered
changing. :wink:

I've recently encountered one project where the coding standard requires
that continuation lines be indented by 1 space, and I found this to be an
issue with clang-format's formatting as well; it would be great to make this
configurable :slight_smile:

I have a sketchy patch for this that I'll try and clean up and post
for review as soon as possible.

The namespace declaration style may be more work, so I'll see if I can
find some time to figure it out once I'm better acquainted with the
code base.

Cheers,
- Kim

Thanks, all!

>>>
>>> 1) As far as I can tell the indentation for continuation lines is
>>> always 4. Is there a strong reason, or could we add a style option for
>>> it?
>>
>> I don't see why it should be a fixed option. Looks like no one bothered
>> changing. :wink:
>
>
> I've recently encountered one project where the coding standard requires
> that continuation lines be indented by 1 space, and I found this to be an
> issue with clang-format's formatting as well; it would be great to make
this
> configurable :slight_smile:

I have a sketchy patch for this that I'll try and clean up and post
for review as soon as possible.

Cool. I certainly agree that this should be an option. We just never got
around to making it one.

The namespace declaration style may be more work, so I'll see if I can

find some time to figure it out once I'm better acquainted with the
code base.

I would guess that this change is much lower value. Usually you would use
clang-format mostly within editors or on patches that you create and these
will rarely contain the namespace declarations. If they do, it is a matter
of hitting "J" a few times in vim ;-).

Cheers,
Daniel

We're considering running clang-format in batch over our entire
codebase, so we're coming at this from a slightly different angle.

I'll see if I can come up with a concrete patch at some point, and
we'll see what the impact is like.

- Kim

>
>> The namespace declaration style may be more work, so I'll see if I can
>> find some time to figure it out once I'm better acquainted with the
>> code base.
>
>
> I would guess that this change is much lower value. Usually you would use
> clang-format mostly within editors or on patches that you create and
these
> will rarely contain the namespace declarations. If they do, it is a
matter
> of hitting "J" a few times in vim ;-).

We're considering running clang-format in batch over our entire
codebase, so we're coming at this from a slightly different angle.

Well, that would also be a good opportunity to get rid of this particular
coding style ;-)..

Slightly more serious, I am all for preserving vertical space as I think it
does matter how much code fits onto a display page. However, such namespace
declarations are almost always in irrelevant parts of the file and the gain
of putting them all in one line is really small.

Cheers,
Daniel

I'll see if I can come up with a concrete patch at some point, and