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

[cpp] bad indentation after macro usage #258

Open
mtaran-google opened this issue Jul 29, 2019 · 5 comments
Open

[cpp] bad indentation after macro usage #258

mtaran-google opened this issue Jul 29, 2019 · 5 comments

Comments

@mtaran-google
Copy link
Contributor

class Foo {
  int z MACRO() = 0;
}

When pressing enter after the ; the indentation goes to column 0, whereas it should ideally stay at column 2. How about even if the mode doesn't know how to handle a given syntax, it'll fall back on keeping the indentation of the previous line (like when CodeMirror smartIndent = false) rather than always going back to column 0?

@marijnh
Copy link
Member

marijnh commented Jul 30, 2019

What would such a macro expand to? Is there anything in C++ that can come between a variable name and its initializer?

@mtaran-google
Copy link
Contributor Author

In clang you can put an annotation there, which is used extensively for thread safety analysis: https://abseil.io/docs/cpp/guides/synchronization#annotation-guidelines

@marijnh
Copy link
Member

marijnh commented Jul 31, 2019

Attached patch should address this case.

Regarding your proposal for indentation, that's not something that's easy to build onto this system, and seems like it would often still do the wrong thing.

@mtaran-google
Copy link
Contributor Author

I disagree about the indentation. Sure, keeping the same indentation might sometimes do the wrong thing. But resetting indentation to 0 will almost always do the wrong thing.

@marijnh
Copy link
Member

marijnh commented Nov 1, 2019

There is no code explicitly resetting the indentation to 0. Zero just happens to be the thing that the indentation code computes from the parse context it gets after the parser has tried to recover from unrecognized syntax, which often leads to it discarding some of the rules it is currently trying to parse.

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

2 participants