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 c-c++ layer respect .clang-format file more closely #13227

Open
samwalls opened this issue Jan 29, 2020 · 8 comments
Open

make c-c++ layer respect .clang-format file more closely #13227

samwalls opened this issue Jan 29, 2020 · 8 comments
Assignees
Labels
C/C++ Feature request Help wanted Indentation stale marked as a stale issue/pr (usually by a bot)

Comments

@samwalls
Copy link

I'm running on the develop branch of spacemacs, using the c-c++ and lsp layers.

I use clang-format for C/C++, I don't know how to configure c-c++ mode to respect more of the clang-format rules as I'm editing. My main issue at the moment is that emacs tries to auto-indent inside the top-level of a namespace scope, whereas if I format the buffer, I get the desired behaviour of no indentation. (I've tried using c-c++-enable-clang-support t as referenced by this issue, but it doesn't do anything).

Similarly, I have to manually set the c-basic-offset to match the project I'm working on. This information is readily available in a clang-format file, so I would imagine it's possible to auto-set these things when a clang-format file is discovered. (This is related to this issue however what I'm asking about has a wider scope).

Is there something I'm missing, or is support for this kind of thing not in spacemacs yet? If not, I think this would be a good feature. Is it feasible?

Other related links:

@thanhvg
Copy link
Contributor

thanhvg commented Jan 29, 2020

In your SO link did you try the solution#2: https://stackoverflow.com/a/55784057 ? If it works we can add it to c-c++ layer.

@alexey0308
Copy link

This is likely due to difference in indentation of line and region functions: lsp assigns only indent-region function to lsp-format-region, but indent-line is c-indent-line, which is called upon newline or other actions.

@smile13241324 smile13241324 removed their assignment Mar 20, 2021
@smile13241324
Copy link
Collaborator

Does not look like I find time to do this, I will add the label for help wanted.

@lebensterben
Copy link
Collaborator

The solution is easier than I thought.

First we already have c-c++-enable-clang-format-on-save which applies clang-format when you save a buffer.

The underlying clang-format package simply calls clang-format executable, which supports -style CLI option that accepts either one of the format style or a .clang-format file.

Therefore what we need here is to lookup for .clang-format file in current directory or one of parent directories (up to the projectile root), and set clang-format-style to the file name.

@lebensterben
Copy link
Collaborator

I propose to extend c-c++-enable-clang-format-on-save and add an additional layer config variable c-c++-clang-format-style, which accepts the following values:

  • one of llvm, gnu, google, chromium, microsoft, mozilla, webKit
  • a filepath pointing to a .clang-format file
  • auto, try to discover a .clang-format file in current project, and don't format if that's not found

@smile13241324
Copy link
Collaborator

Sounds good

@janemba
Copy link

janemba commented Oct 18, 2023

is it fixed ? if yes how ?

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ Feature request Help wanted Indentation stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

7 participants