guess-indent.nvim
guess-indent.nvim copied to clipboard
Google C++ style
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?
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).
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.
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 https://github.com/NMAC427/guess-indent.nvim/blob/b8ae749fce17aa4c267eec80a6984130b94f80b2/lua/guess-indent/init.lua#L272.
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.
@agronskiy Thank you for this nice solution, I'll give it a try.