vim-autoformat / vim-autoformat

Provide easy code formatting in Vim by integrating existing code formatters.
MIT License
2.25k stars 178 forks source link

Search user-level clang-format config #347

Closed myl7 closed 3 years ago

myl7 commented 3 years ago

Putting a .clang-format file in every C++/C project is troublesome, and single file C++/C test-purpose projects are common. There are also widely-used C++/C code styles like Google that may be used in someone's almost all projects.

The PR tries to search ~/.clang-format and ~/_clang-format after searching .clang-format and _clang-format.

Though this is not standard behavior of clang-format, the PR may make it more convenient for developers.

chtenb commented 3 years ago

Though this is not standard behavior of clang-format

If this is not standard behavior, how will clangformat take these file locations into account?

myl7 commented 3 years ago

According to the doc, clang-format will use the .clang-format file located in the closest parent directory, so ~/.clang-format may be used if the project is in the home dir and no other .clang-format files are found.

As the plugin checks .clang-format in the current dir to determine whether to apply the default generated clang-format style options, I think additionally searching ~/.clang-format may make sense.

chtenb commented 3 years ago

So this change breaks the case where the current project is not beneath the home folder while a ~/.clang-format still exists. But since this sounds very unlikely (why would you have ~/.clang-format if vim-autoformat doesn't look at it) I think this can be merged.