如何禁用影响宏的clang格式设置



在clang格式的设置/样式文件中,根据函数的可接受样式指导线来选择设置。但是,它也会格式化。我希望不被格式化,而函数是根据设置格式化的。如何实现所需格式?

我有这个:

//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

更新:只有当存在多行宏时才会出现这种效果。

我找到了一个CLang Format选项,可以解决您的问题。该选项称为AlignEscapedNewlines,默认情况下设置为Right。但是,将其设置为DontAlign可能有助于解决您的问题。

AlignEscapedNewlines: DontAlign

相关内容

  • 没有找到相关文章

最新更新