Auto formatting .clang-format

I have successfully edited the .clang-format file to have my brackets to line up properly.

... except for array assignments:

 const char *exmp[] = {
    "Example",
    "Example too"
};

I want:

const char *exmp[] = 
{
    "Example",
    "Example too"
};

What is the line in the .clang-format file that governs this?

When I looked at this I had high hopes of the BraceWrapping: setting and its custom settings, but none seem to fit the bill

I suspect that you, like me, have used BreakBeforeBraces: Allman which unfortunately does not affect the braces in array assignments

Please update this topic if you find out how to do it

1 Like

Yes, your .clang-format file with proper comments put me on the right track.

Unfortunately I find the original file a mere hacker soup, composed by people who believe everything is self-evident so nothing needs to be explained..

The closest I got was

const char *exmp[] =
  {
    "Example",
    "Example too",
};

You have to place the opening brace on the newline yourself and the indent after an autoformat is annoying; you also need to add the comma after the last element (but I think that that can be done automatically with a setting.
.
The settings

BreakBeforeBraces: Allman
Cpp11BracedListStyle: true

Everything is explained in great detail in the extensive ClangFormat documentation:

https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html

It would be silly to attempt to maintain parallel documentation in comments in the .clang-format file.

I have written some supplemental notes for specific settings where I found the ClangFormat documentation inadequate:

ptillisch wrote "Everything is explained in great detail in the extensive ClangFormat documentation. It would be silly to attempt to maintain parallel documentation in comments in the .clang-format file."

Ok, that's great. Yet I wonder why the link to the very documentation is missing from the header in the .clang-format file.

If it were in place none of this forum conversation would have taken place ...

The documentation is linked from the tutorial page:

https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-customize-auto-formatter#setting-the-custom-configuration

The formatter tool used by Arduino IDE 2.0 is ClangFormat. The documentation for the configuration options is here.

Ok, for you everything is self-evident. Please put a link to the documentation in the .clang-format file for us stupid people. Please?

1 Like

Thousands of possible combinations of options, many of which are opaque at best. Oh how I wish there was a simple PutAllBracesOnTheirOwnLine setting but that would be much too simple

2 Likes

where is this clang format file? is something I download, or is already in the ide?

It is in C:\Users<username>.arduinoIDE if you are using Windows

Take note of the full stop in the filename

Not by default as far as I remember

@Don-T, you can download it from https://raw.githubusercontent.com/arduino/tooling-project-assets/main/other/clang-format-configuration/.clang-format

sterretje
i found your zip file of .clang-format on another thread. i put it in my arduino ide as you said and i think it's working. so i wanted to say Thank you.
question how do i open it to edit some of the settings?

Use a text editor like Notepad++ or even Notepad

You can open it with any decent text editor. I mostly use notepad++ (not notepad) under windows.

I found this clang-format configuration tool.
You select the version, 14 for Arduino IDE, and test out your changes with changes shown live in sample code, then download your config file.

2 Likes

That looks very useful. Thanks :+1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.