On Wed, May 15, 2013 at 5:43 PM, Anthony Martin <
al...@pbrane.org> wrote:
> Dmitry Vyukov <
dvy...@google.com> once said:
>> I am looking into using clang-format for auto-formatting of C code in
>> runtime and commands:
>>
http://clang.llvm.org/docs/ClangFormat.html
>>
>> Here is an example of what it currently does with runtime:
>>
https://codereview.appspot.com/9222047/
>>
>> I've talked to developers and they are willing to accept more style tweaks.
>> After briefly looking at diffs, the main things are:
>> - return type on function definition must be on a separate line
>> - no space between "if ("
>> But most likely there are still will be differences, because some
>> formatting rules that we use are difficult to express, e.g. spacing in
>> "n*m + x". But I think benefits of stable auto-formatting outweigh it.
>>
>> If we incorporate it into presubmit, all C hackers will need
>> clang-format in PATH.
>>
>> What do you think?
>
> Here's the things I don't like about it. You already called out
> most of them.
>
> 1. In struct definitions it doesn't align the field names and it
> sticks the '*' for pointers onto the field instead of the type
> where it belongs.
Probably we can introduce a parameter for this.
> 3. It inserts too many spaces. I'd rather it be like gofmt and
> format "a + x * y" as "a + x*y".
WIll it do if we just split all operators into 2 groups -- insert
space around, and do not insert spaces around?
> 2. The return type of a function definition is on the same line.
> This is really annoying if you're using Acme. You can no longer
> get to a function by plumbing filename:/^function.
We need a parameter for this. It is quite common style.
> 4. Again with the spaces. This time after "if", "while", "for",
> and "switch".
We need a parameter for this.
> 5. Comments are handled in an odd manner. See line 158 of the
> malloc.goc file in your CL.
This actually looks like a bug. I will ping developers.
> Other than that, I think it's a fine idea.
>
> There's a program from Plan 9 called cb which already formats C
> code into our style. Alternatively, we could just use that.
Can you post a link to more info about cb? Does it work on other OSes?
Btw, is there some "official" name for the style? Plan9?