Add a .clang-format file

It gets hard to code in GNU style for people with editors that don't
understand the difference between indentwidth and tabstop.

This file is based on gcc's contrib/clang-format. A flaw of it is that
it does not put a space after selector colons. I am gonna file a LLVM
bug for that.
This commit is contained in:
Mingye Wang 2020-02-18 22:26:25 +08:00
parent c8cfcec652
commit af38713702

77
.clang-format Normal file
View file

@ -0,0 +1,77 @@
# Copyright (C) 2015 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Modified from gcc's clang-format config.
# clang-format 7.0.1 is required
#
# To utilize the tool to lines just touched by a patch, use
# clang-format-diff script that is usually also packaged with clang-format.
#
# Example of usage:
# git diff -U0 --no-color | clang-format-diff -p1
# (here the tool will generate a patch)
# git diff -U0 --no-color | clang-format-diff -p1 -i
# (modifications are applied)
---
AccessModifierOffset: -2
AlwaysBreakAfterReturnType: TopLevel
AlignConsecutiveDeclarations: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
# Newer clang-format has BS_GNU
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: false
BreakBeforeTernaryOperators: true
ColumnLimit: 80
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ForEachMacros: []
IndentCaseLabels: false
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 100
DerivePointerAlignment: false
PointerAlignment: Right
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 1
UseTab: Always
AlignEscapedNewlines: Right
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: MultiLine
KeepEmptyLinesAtTheStartOfBlocks: false
# TODO
# MacroBlockBegin:
# MacroBlockEnd: