codemirror / google-modes

A consistent set of modes for C, C++, Java, Go, JavaScript, TypeScript, Python, HTML, and Angular Templates
MIT License
33 stars 28 forks source link

[cpp] bad indentation after macro usage #258

Open mtaran-google opened 5 years ago

mtaran-google commented 5 years ago
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 commented 5 years ago

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

mtaran-google commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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.