Comments (16)
Seems to work for me, if you just switch to lower-case c++14
instead:
let g:clang_format#style_options = {
\ "AccessModifierOffset" : -4,
\ "Standard" : "c++14"}
(Looks like upper-case C was regarded as legacy after C++11: https://github.com/llvm-mirror/clang/blob/65acf43270ea2894dffa0d0b292b92402f80c8cb/lib/Format/Format.cpp#L77)
Can you confirm?
from vim-clang-format.
To me it looks like the version of clang-format you use do not include the commit I mentioned. Are you using 9.0.1? If I am reading it correctly, you need 10.0.0-rc1 to get the c++14 attribute.
from vim-clang-format.
@Kypert , I just followed your suggestion to scale down. Found that set tabstop=4
and set shiftwidth=4
vim .vimrc
is the root cause. Thanks a million.
from vim-clang-format.
Seems no activity in this repo. I have reverted to clang-format.py
solution. So far so good.
map <C-K> :py3file /usr/share/clang/clang-format.py<cr>
from vim-clang-format.
@Kypert Confirmed that only when g:clang_format#style_options
is removed, ClangFormat
will work. Lower case does not work for me either. Sad
from vim-clang-format.
Perhaps you can obtain more clear information by running: :ClangFormatEchoFormattedCode
from vim-clang-format.
@Kypert Cool. It's clear now. But I do not know how to fix. Could you throw some light upon this?
YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}
^~~~~~~
Error parsing -style: Invalid argument
from vim-clang-format.
Thank you for the output. Could you please share the version of the clang-format that you are trying to invoke? Did you point to a certain version via g:clang_format#command
?
Could it be that you are using a version of clang-format that does not include llvm/llvm-project@e503256?
You can also try to run the command manually with your style, to isolate the problem:
> echo test > testfile
> clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}" -- testfile
test
from vim-clang-format.
Tried your test case, but it failed to format.
I am using Arch Linux. clang-format
is provided by package clang
. llvm
is also installed.
➜ ~ cat testfile
test
➜ ~ clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}" -- testfile
YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}
^~~~~~~
Error parsing -style: Invalid argument
➜ ~
from vim-clang-format.
Even if I changed Standard to c++11, the same error occurred. But upper case C++11
works!
clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++11'}" -- testfile
YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++11'}
^~~~~~~
Error parsing -style: Invalid argument
from vim-clang-format.
But upper case C++11 works!
Makes sense, since the lower-case versions were added in the commit I mentioned. I think we have a case-closed situations :) Please update your clang-format binary or adapt the config.
from vim-clang-format.
There is another problem that I didn't mention earlier. Invoking :ClangFormat
from vim doesn't format the code correctly. While clang-format
command line works. The incorrect format result is as follows. You can see that the indentation of line 107 is wrong. I didn't set g:clang_format#style_options
in .vimrc
int main() {
99 std::vector<float> nums(10);
100 std::copy(nums.begin(), nums.end(),
101 std::ostream_iterator<float>(cout, " "));
102 cout << '\n';
103 return 0;
104 Solution solution;
105 std::string digits;
106 while (std::getline(cin, digits)) {
107 cout << solution.digitsToChinese(digits) << endl;
108 }
from vim-clang-format.
Sorry, not sure how to tackle that one. Like you said, it is another problem indeed, maybe check :ClangFormatEchoFormattedCode
? Can you see if other parts of the code get formatted, like if you introduce extra spaces on other lines?
from vim-clang-format.
Surprised. :ClangFormatEchoFormattedCode
shows rightly formatted code. Quite confused now :P
from vim-clang-format.
Could it be that another plugin is interfering, would it be possible to scale down and see if the issue goes away at some point? Maybe you already solved it?
from vim-clang-format.
Upgraded to clang 10.0.0-2, now Standard" : "c++17"
is recognized.
from vim-clang-format.
Related Issues (20)
- How to write style_option??? HOT 8
- Can vim-clang-format correctly indent as I write code? HOT 2
- How to set the indent after #define HOT 5
- last edit mark is tampered after ClangFormat HOT 3
- Overriding an option from .clang-format HOT 1
- ClangFormatAutoEnable to only format surrounding unsaved buffer
- Error when running ClangFormat in neovim HOT 3
- Working with CUDA
- :ClangFormat kills vi HOT 1
- Recommend installation command
- There's a problem with formatting HOT 1
- selected code formatting in visual mode isnt working. HOT 1
- How can I disable auto_format_on_insert_leave in some special case
- stderr clang-format output got pasted into the source file
- Useful information
- Doesn't work on AstroNeoVim
- Support vala langauge? HOT 3
- Bug: undo after ClangFormat does undo twice, erasing previous changes HOT 9
- Detect if file is formattable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-clang-format.