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

:ClangFormat always folds code when run

Open cglosser opened this issue 7 years ago • 3 comments

Is there a way to run the formatter without triggering automatic code folding? Presumably this happens because I have vim setup to fold code when opening a C++ file and :ClangFormat reopens the file after it has done its thing. It would be great if vim-clang-format had some way to disable this so as to avoid having to drill down through a bunch of folds.

cglosser avatar Jun 29 '17 16:06 cglosser

I noticed that it's hard to maintain folding between the before and the after of formatting. For example, when a formatter found unnecessary { ... } block (e.g. body of if statement), it would remove the block. Removing block means the change of folding level. We can't detect it from Vim and vim-clang-format can't know which fold level it should open.

However, closing all folds after formatting is annoying as you pointed. I think I can try to implement some heuristics to reduce the problem, although it's not perfect.

rhysd avatar Jun 30 '17 05:06 rhysd

I added code to maintain fold level at cursor line as much as possible in 1cf402c. Please try the latest and check the behavior is what you want.

rhysd avatar Jun 30 '17 05:06 rhysd

I haven't noticed any difference in behavior, but that could easily be due to other settings I have. Do you have an example I can check?

cglosser avatar Jul 05 '17 17:07 cglosser