Как отключить настройки формата clang, влияющие на макросы? - PullRequest
1 голос
/ 24 октября 2019

В файле настроек / стилей формата 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

Обновление: этот эффект происходит только при наличии многострочного макроса.

...