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

Make style lookup consistent with clang-format #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arntanguy
Copy link

The current version was only

  • looking up .clang_format in the file's directory.
  • using -style=file option only, causing failure if pwd != file's
    directory

This behavior is quite problematic as it can easily lead to using the wrong .clang-format file, ie the one
in your current pwd instead of the one in the file's project. There are also some obvious cases
where the .clang-format file isn't found.

This commit makes the behavior fully consistent with clang-format:

  • lookup .clang_format into the file's directory and recursively go up
    its parent directory until found. If no style file is found, defaults
    to g:clang_format#style_options

I don't really know the Viml language, so please double check if it's written the vim-way.

The current version was using -style=file option only,
causing failure if pwd != file's directory.
2 kinds of failures occur:
- If no .clang-format is present in PWD, and one is
present in the file's directory, then clang-format
fails for lack of style file, and dump its error message
directly into the buffer
- If a .clang-format is present in PWD, and one is present
in the file's directory, then the wrong .clang-format from PWD is used

This commit makes the behavior fully consistent with clang-format:
- lookup .clang_format in the file's directory and recursively go up
its parent directory until found. If no style file is found, defaults
to g:clang_format#style_options
@arntanguy
Copy link
Author

My apologies, I should have looked at the documentation more carefully.
Here is the corrected version.

@arntanguy
Copy link
Author

I'm not sure you saw my answer regarding the versions of clang supporting this, so I'll write it here again.

I'm not sure when it --assume-filename got introduced, but clang-3.4 (that you list as dependency in the README) definitely has it.
It seems to be a pretty sensible feature to have, so I would assume it's been there since the first releases of clang-format, but we never know.

Also in clang-format-3.6, there is a -fallback-style that can fallback to any of the preset styles (llvm, google...) if all else fails. This doesn't seem to be in 3.4, so I haven't used it for that pull-request.

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

Successfully merging this pull request may close these issues.

1 participant