How to auto indent a C++ class with 4 spaces using clang-format?

As near as I can tell, clang-format offers no option for indenting function contents differently from non-access-modifier class contents. That is, consider the following code: class A { public: void foo() {} } void bar() { int a; } In this code, the line “void foo() {}” will always be indented the same amount as … Read more

Indenting preprocessor directives with clang-format

As of version 6.0, the option IndentPPDirectives can be used. Usage is described in this review. Using IndentPPDirectives: None results in: #if FOO #if BAR #include <foo> #endif #endif While IndentPPDirectives: AfterHash gives: #if FOO # if BAR # include <foo> # endif #endif Edit: see @Gabriel Staples’ answer for details on the BeforeHash option … Read more

How can I apply only one clang-format action?

I think clang format was simply not designed for this. Rules are not things it applies incrementally, the program is instead built around, parsing your entire program and forgetting (most of) the old whitespace, and generating new whitespace based on the rules you select. You can see some overview of the architecture here: http://www.llvm.org/devmtg/2013-04/jasper-slides.pdf First … Read more

Why are my Xcode plugins (such as clang format) installed with Alcatraz no longer working after updating to new version of Xcode?

Oftentimes, the following helps: Re-install Alcatraz, restart Xcode, de-install and re-install your plugin. Sometimes it helps to restart Xcode again. This worked for me. If your plugin still does not show up, the problem is probably that the the compatibility key of your new Xcode is not yet included in the list of compatibility keys … Read more

how to make clang-format add new line before opening brace of a function?

As the documentation says, invoke clang-format with -style=file, and use a .clang-format file placed in an enclosing directory to customize style options. The format style option specifying brace placement is called BreakBeforeBraces. From the docs, BreakBeforeBraces (BraceBreakingStyle) The brace breaking style to use. Possible values: BS_Attach (in configuration: Attach) Always attach braces to surrounding context. … Read more

Using clang-format in CLion

You can use External Tools in CLion. Go to File->Settings->Tools->External Tools and click on the plus sign. A window should pop up. Use a name of your choice. For the Tool settings tab I’m using this configuration: Program: clang-format-3.7 (you should use the name of your executable here) Parameters: -i $FileName$ Working directory: $FileDir$ Now, … Read more