vim-clang-format icon indicating copy to clipboard operation
vim-clang-format copied to clipboard

How to set the indent after #define

Open irreallich opened this issue 5 years ago • 5 comments

I read the http://clang.llvm.org/docs/ClangFormatStyleOptions.html and do lots of test , but I don't know how to set the following style: don't care about the '\', it is correct on my pc ,and I don't know how to make it correct in the markdown. expect:

#define AUTO_CTL(name)                                                                      \
{                                                                                                              \
     #name, name##_cb                                                                           \
}

now:

#define AUTO_CTL(name)                                                                      \
    {                                                                                                          \
        #name, name##_cb                                                                        \
    }

irreallich avatar May 10 '20 15:05 irreallich

It seems like the continuation of the macro is treated as a new indentation level by clang-format, like adding another pair of { } would too. But ultimately, not much that this plugin can do for you in this scenario, I think.

Kypert avatar May 12 '20 17:05 Kypert

@Kypert thanks for your reply, I agree with you , it is the problem about how to use clang-format. but in the plugin, 'BreakBeforeBraces' : 'Allman', can be used to set up for the braces, and there are lots of sub settings after it if I set BreakBeforeBraces as 'custom', but I try to do so, the plugin report error

irreallich avatar May 15 '20 01:05 irreallich

Would you mind share the exact style_options? Did you make sure that you used Custom with upper-case C?

Kypert avatar May 16 '20 09:05 Kypert

@Kypert I am very sorry for the late reply now I share two settings, the original issue can be reproduced both of them

the following is my settings now, BreakBeforeBraces is 'Allman'

 25     let g:clang_format#code_style='llvm'
 26     let g:clang_format#style_options = {}
 27     let g:clang_format#style_options.TabWidth = 4
 28     let g:clang_format#style_options.UseTab = 'Never'
 29     let g:clang_format#style_options.IndentWidth = 4
 30     let g:clang_format#style_options.IndentPPDirectives = 'BeforeHash'
 31     let g:clang_format#style_options.AccessModifierOffset = -4
 32     let g:clang_format#style_options.BreakBeforeBraces = 'Allman'
 33     let g:clang_format#style_options.AllowShortIfStatementsOnASingleLine = 'false'
 34     let g:clang_format#style_options.IndentCaseLabels = 'true'
 35     let g:clang_format#style_options.AllowShortFunctionsOnASingleLine = 'false'
 36     let g:clang_format#style_options.AlignConsecutiveDeclarations = 'true'
 37     let g:clang_format#style_options.AlignConsecutiveMacros = 'true'
 38     let g:clang_format#style_options.AlignTrailingComments = 'true'
 39     let g:clang_format#style_options.BinPackArguments = 'false'
 40     let g:clang_format#style_options.BinPackParameters = 'false'
 41     let g:clang_format#style_options.ColumnLimit = '80'
 42     let g:clang_format#style_options.Standard = 'C++11'
 43     let g:clang_format#style_options.AlignEscapedNewlines = 'Right'
 44     let g:clang_format#style_options.AlignConsecutiveAssignments = 'true'

the following is my test settings,
47 function! Vbackup_func() 48 let g:clang_format#code_style='llvm' 49 let g:clang_format#style_options = { 50 \ "TabWidth" : 4, 51 \ "UseTab" : 'Never', 52 \ "IndentWidth" : 4, 53 \ "IndentPPDirectives" : 'BeforeHash', 54 \ "AccessModifierOffset" : -4, 55 \ "AllowShortIfStatementsOnASingleLine" : 'false', 56 \ "IndentCaseLabels" : 'true', 57 \ "AlignConsecutiveDeclarations" : 'true', 58 \ "AlignConsecutiveMacros" : 'true', 59 \ "AlignTrailingComments" : 'true', 60 \ "BinPackArguments" : 'false' , 61 \ "BinPackParameters" : 'false', 62 \ "ColumnLimit" : 80, 63 \ "Standard" : 'C++11', 64 \ "AlignEscapedNewlines" : 'Right', 65 \ "AlignConsecutiveAssignments" : 'true', 66 \ "AlignAfterOpenBracket" : 'DontAlign', 67 \ "BreakBeforeBraces" : 'Custom', 68 \ } 69 70 "\ "PPDirectiveIndentStyle" : 'None', 71 72 "let g:clang_format#style_options.BreakBeforeBraces = 'Allman' 73 if g:clang_format#style_options.BreakBeforeBraces == 'Custom' 74 ¦ "手动设置大括号之前的换行 75 ¦ let g:clang_format#style_options.BraceWrapping = { 76 ¦ \ "AfterClass" : 'true', 77 ¦ \ "AfterControlStatement" : 'true', 78 ¦ \ "AfterEnum" : 'true', 79 ¦ \ "AfterFunction" : 'true', 80 ¦ \ "AfterNamespace" : 'true', 81 ¦ \ "AfterObjCDeclaration" : 'true', 82 ¦ \ "AfterStruct" : 'true', 83 ¦ \ "AfterUnion" : 'true', 84 ¦ \ "AfterExternBlock" : 'true', 85 ¦ \ "BeforeCatch" : 'true', 86 ¦ \ "BeforeElse" : 'true', 87 ¦ \ "IndentBraces" : 'false', 88 ¦ \ "SplitEmptyFunction" : 'false', 89 ¦ \ "SplitEmptyRecord" : 'false', 90 ¦ \ "SplitEmptyNamespace" : 'false', 91 ¦ \ } 92 endif 93 endfunction

irreallich avatar Oct 16 '20 02:10 irreallich

Sorry, i missed this reply. Yearly update :)

From my understanding, the plugin error was when you tried to set the different BraceWrapping options, which is nested - but it looks like you have figured that part out.

When it comes to the indent after the escaped-newline in a macro, I think you have to turn to clang-format and request this option. I too am unable to find the suitable option knob for that in current clang-format version (was checking clang11).

Kypert avatar May 14 '21 12:05 Kypert