Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the indent after #define #105

Open
irreallich opened this issue May 10, 2020 · 5 comments
Open

How to set the indent after #define #105

irreallich opened this issue May 10, 2020 · 5 comments

Comments

@irreallich
Copy link

irreallich commented May 10, 2020

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                                                                        \
    }
@Kypert
Copy link

Kypert commented May 12, 2020

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.

@irreallich
Copy link
Author

@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

@Kypert
Copy link

Kypert commented May 16, 2020

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

@irreallich
Copy link
Author

@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

@Kypert
Copy link

Kypert commented May 14, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants