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

Google C++ style #15

Open
zhongsanming opened this issue May 6, 2023 · 4 comments
Open

Google C++ style #15

zhongsanming opened this issue May 6, 2023 · 4 comments

Comments

@zhongsanming
Copy link

zhongsanming commented May 6, 2023

Google C++ style place class member access specifier in 3 spaces indent, which make guess-indent set indent to 1 space. In practice this should be 4 spaces.
A simple example:

class Example {
   public:
    Example() {}
};

can we support this as a special case?

@zhongsanming zhongsanming changed the title Google C++ style problem Google C++ style May 6, 2023
@NMAC427
Copy link
Owner

NMAC427 commented May 6, 2023

Thanks for letting me know. I'm not yet sure how to best fix this issue.
I have an idea on how I could modify the heuristic, but I'm worried that it might make it worse overall.

I created a new branch with a modified heuristic which works better with the Google C++ style, though it still tails with the example you provided (it is too short).

@zhongsanming
Copy link
Author

zhongsanming commented May 8, 2023

I don't know much lua or nvim plugin writing or ident detect, can we maybe just ignore access modifiers? Let say if a C++ line matches regex "^\s*(private|public|protected)\s*:\s*$", then skip this line.

@agronskiy
Copy link

agronskiy commented Jun 11, 2023

Hey @zhongsanming, a fellow C++ Google Style Guide user here. I arrived here because of a different problem (in Neovim 0.8 without editorconfig.nvim plugin, the guess-indent.nvim failed to respect my EditorConfig -- now solved), but here's a solution we happily use in our codebase:

just add an .editorconfig to your root directory of the project, with approx the following content:

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[*.{h,cpp}]
indent_style = space
indent_size = 4

AND in case you are under 0.9 version of Neovim, install gpanders/editorconfig.nvim so the guess-indent understands the buffer vim.b.editorconfig variable here

local editorconfig = vim.b.editorconfig
.

After that, the guess-indent should be good! My justification is that Google Style Guide is quite nontrivial in that part and having editorconfig anyways helps.

@zhongsanming
Copy link
Author

@agronskiy Thank you for this nice solution, I'll give it a try.

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

No branches or pull requests

3 participants