Closed ghost closed 6 years ago
I think there is nothing I have done with the commands as long as .clang-format
is in the folder higher than the file that needs formatting. Also need to add c-c++
layer with clang-options set
(c-c++ :variables
**c-c++-enable-clang-support t**
c-c++-default-mode-for-headers 'c++-mode)
Then ,==
does the formatting.
@dubnde Well I've got these lines in my dotspacemacs-configuration-layers
(c-c++ :variables
c-c++-enable-clang-support t
c-c++-enable-clang-format-on-save t)
But still the indentation is off... The rest of the formatting seems to work though. I suspect emacs is doing some crazy stuff on the background...
Edit:
And yes the .clang-format
is in the top level folder.
Tried your config and doesn't work for me either. But then I am using clang-6
so some of the config parameters may have changed. For what it is worth below is my configuration with indent/tab (2) :
Language: Cpp
BasedOnStyle: WebKit
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ foreach, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(boost|cpputest|gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 10000
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 2
UseTab: Never
I'm on clang 6.0.0 as well and the clang-format works fine for me, except the indentation issue...
Ouput clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
As stated this clang-format is directly taken from the kernel tree, so I doubt there are errors in it. Running clang-format <filename>
from the terminal yields proper and expected results though.
I will try your config, thanks for sharing!
Hopefully I can figure it out, but I do think it is emacs doing some crazy stuff in the background, like mentioned here...
Okay i figured it out... This was really embarrassing, if you have both a .clang-format and a .editor-config, you'll see the tab/space width as specified in the .editorconfig, even if the clang-format(ting) is done correctly.
This seems to be no spacemacs issue, but a configuration issue in my project, closing this issue...
@dubnde, thanks for thinking with me, it let me find this "indirection" faster.
@SirJls thanks for the update. Good to learn that editor config may need to be aligned with using clang-format.
I am scratching my head over this issue for some hours now, but I am not able to figure out why spacemacs does not properly ident my file with an 8 character indent.
Running
clang-format my-file-name
from the terminal does give me the correct results, but using one of the two following commands yields an improper indented region/buffer.I've taken a look at similar problems, but none seem to answer my question.
(setq c-basic-offset 8)
also seems to yield no wishful results.Maybe I am going over it wrong, but I would gladly like to get some suggestions and/or possible fix.
I am currently using the upstream HEAD of the develop branch of spacemacs.
git rev-list HEAD | head -n1
= 8f82486154f828d3b805c5c349e41b82c801d2c8The clang-format file is as follows (directly taken from the kernel tree):