git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] .clang-format: introduce the use of clang-format

From
René Scharfe <l.s.r@web.de>
Date
Jan 18, 2015, 11:31 UTC
Message-ID
<54BB9986.2040706@web.de>
In-Reply-To
<1421530221-39306-1-git-send-email-artagnon@gmail.com>
Am 17.01.2015 um 22:30 schrieb Ramkumar Ramachandra:
Show 33 quoted lines
> Instead of manually eyeballing style in reviews, just ask all
> contributors to run their patches through [git-]clang-format.
>
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>   The idea is to introduce the community to this new toy I found called
>   clang-format. Whether or not it's actually going to be used doesn't
>   bother me too much.
>
>   I'm not 100% sure of the style, but I'll leave you to tweak that
>   using http://clang.llvm.org/docs/ClangFormatStyleOptions.html
>
>   The current code isn't terribly conformant, but I suppose that'll
>   change with time.
>
>   .clang-format | 7 +++++++
>   1 file changed, 7 insertions(+)
>   create mode 100644 .clang-format
>
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 0000000..63a53e0
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,7 @@
> +BasedOnStyle: LLVM
> +IndentWidth: 8
> +UseTab: Always
> +BreakBeforeBraces: Linux
> +AllowShortBlocksOnASingleLine: false
> +AllowShortIfStatementsOnASingleLine: false
> +IndentCaseLabels: false
> \ No newline at end of file
Why no newline on the last line?
These one would be needed as well to match our style, I think:
	AllowShortFunctionsOnASingleLine: None
	ContinuationIndentWidth: 8
And probably this one:
	Cpp11BracedListStyle: false

However, even then struct declarations that are combined with variable declaration and initialization get mangled:

	struct a {
		int n;
		const char *s;
	} arr[] = {
		{ 1, "one" },
		{ 2, "two" }
	};
becomes:
	struct a
	{
		int n;
		const char *s;
	} arr[] = { { 1, "one" }, { 2, "two" } };
It gets formatted better if arr is declared separately.

And this one helps get rid of the added line break between struct a and the following brace:

	BreakBeforeBraces: Stroustrup
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 2 of 7 in “.clang-format: introduce the use of clang-format”
  1. .clang-format: introduce the use of clang-formatRamkumar Ramachandra, Jan 17, 2015
  2. René ScharfeJan 18, 2015
  3. Ramkumar RamachandraJan 21, 2015
  4. .clang-format: introduce the use of clang-formatRamkumar Ramachandra, Jan 21, 2015
  5. Jeff KingJan 21, 2015
  6. Ramkumar RamachandraJan 21, 2015
  7. Jeff KingJan 21, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.