More clang-format options please ?

Hello,

Is it possible to add a clang-format option for the indent to use inside preprocessing directives please ? So I could use an indent of 1 for the PP, and 4 for the rest of the language

#if defined(_DEBUG)

include “assertions.hh”

#endif

Also is it possible please to add an option for indenting the template header ? Similar to IndentRequires, but it would apply to the following line, so I can write:

template
class vector
{
// …

and:

template
ArgT max(ArgT const &a, ArgT const &b)
{
return a < b ? b : a;
}

Next, could I also break on function call and function definition parentheses, like I can brake on braces ? So I can write:

void loadContainerFromStorage
(
string storageFileName,

Cont &container,
size_t &container_size
)
{
// …

And then the same case for template arguments…

Hi,

Hello,

Is it possible to add a clang-format option for the indent to use inside preprocessing directives please ? So I could use an indent of 1 for the PP, and 4 for the rest of the language

Something like PPIndentWidth (https://clang.llvm.org/docs/ClangFormatStyleOptions.html) ? :slight_smile:

#if defined(_DEBUG)
# include "assertions.hh"
#endif

Also is it possible please to add an option for indenting the template header ? Similar to IndentRequires, but it would apply to the following line, so I can write:

Make a whish, Bugzilla (or GitHub?) and add me (HazardyKnusperkeks) or MyDeveloperDay. Maybe someone will take care of it.

template <typename ElementT>
class vector
{
// ...

and:

template <typename ArgT>
ArgT max(ArgT const &a, ArgT const &b)
{
return a < b ? b : a;
}

Next, could I also break on function call and function definition parentheses, like I can brake on braces ? So I can write:

void loadContainerFromStorage
(
string storageFileName,
Cont &container,
size_t &container_size
)
{
// ...

I think something like this is in work, you can look in phabricator: https://reviews.llvm.org/differential/query/q_PaOIrQOjwt/

And then the same case for template arguments...

--
Thank you,
Timothy Madden

Kind regards,
Björn Schäpers.

Is it possible to add a clang-format option for the indent to use inside
preprocessing directives please ? So I could use an indent of 1 for the PP, and
4 for the rest of the language

Something like PPIndentWidth
(https://clang.llvm.org/docs/ClangFormatStyleOptions.html) ? :slight_smile:

Yep, this was added to trunk just like a month ago, in the LLVM 14 timeframe.
FWIW, this option was of interest to libc++ (and I believe we turn it on), but it’s still not perfect for our use-cases. It has trouble with the fuzzy idea of “being in a new context,” e.g. it will do this:

#ifndef FOO

#define FOO

int foo();

#if BAR

int bar() {

baz();

if BAZ_TWICE

baz();

endif // BAZ_TWICE

return 0;

}

#endif // BAR

#endif // FOO

It understands that the header guard is special and doesn’t force-indent everything inside it; but it isn’t currently capable of applying the same logic to the BAZ_TWICE section: to say “okay, the BAR business is located entirely outside this function and doesn’t affect the stuff inside it.” It’s going to treat BAZ_TWICE as “nested by one level,” even though a human programmer wouldn’t generally think of it that way.
(FWIW, it makes perfect sense that a machine would think of it that way; I mean I get why clang-format does this. I might even thank it for doing this, in some pathological cases. But it doesn’t result in very aesthetically pleasing results in the non-pathological cases.)

Further nit-that-maybe-should-be-a-bug-report-instead-of-an-email :slight_smile:
It would be helpful if the documentation for PPIndentWidth mentioned that setting PPIndentWidth will take effect only if you also set IndentPPDirectives; and IndentPPDirectives should mention that the indent level is controlled by (IndentWidth and) PPIndentWidth.

Also is it possible please to add an option for […]
template
class vector
{

FWIW, I’d urge you to take clang-format’s lack of support here as a hint, and reformat your code in a style that’s closer to common industry practice. :wink:

my $.02,
Arthur