在clang格式的设置/样式文件中,选择的设置与 functions 接受的样式指导行一致。但是,它也会格式化 macros。我希望在根据设置格式化 functions 时不格式化 macros。如何实现所需的格式?
我有这个
//macros
#define RET printf("\n")
#define TAB printf("\t")
#define QUERY \
{ \
char c; \
if(!NoQUERYS) { \
printf("Continue (Y/N)?"); \
c = toupper(_getch()); \
RET; \
if(c != 'Y') exit(1); \ //looks not good(takes too much space)
} \
}
#define PRESSKEY \
{ \
char c; \
if(!NoQUERYS) { \
printf("Press any key to continue."); \
c = _getch(); \
RET; \
} \
}
//function
int fwind2param(FILE* txt)
{
while( !feof(txt) ){ //looks good
fgets( s, 255, txt );
}
}
我想要这个
//macros
#define RET printf("\n")
#define TAB printf("\t")
#define QUERY {char c; if(!NoQUERYS){ printf( "Continue (Y/N)?" );c=toupper(_getch());RET;if(c!='Y')exit(1);}}
#define PRESSKEY {char c; if(!NoQUERYS){ printf( "Press any key to continue." );c=_getch();RET; }}
//above formatting of macros looks good
//function
int fwind2param(FILE* txt)
{
while( !feof(txt) ){ //looks good
fgets( s, 255, txt );
}
}
我的clang格式文件如下所示:
# Abgeänderte .clang-format-Datei
# Anhaltspunkt ist https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# sowie: https://clangformat.com
#for visual studio 2017 you have to comment this one thing:
#BreakInheritanceList: AfterColon
#version for visual studio 2019:
#Language: Cpp
BasedOnStyle: llvm
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
#BreakInheritanceList: AfterColon
ColumnLimit: 300
DerivePointerAlignment: false
DisableFormat: false
SortIncludes: false
IndentCaseLabels: true
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
PointerAlignment: Right
ReflowComments: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: true
TabWidth: 2
UseTab: Never
更新:此效果仅在存在多行宏时发生。
1条答案
按热度按时间kr98yfug1#
我找到了一个可以解决您的问题的CLang格式选项。该选项名为
AlignEscapedNewlines
,默认设置为Right
。但是,将其设置为DontAlign
可能有助于解决您的问题。AlignEscapedNewlines: DontAlign