Open XO39 opened 3 years ago
The current implementation determines indentation by calculating the change in depth of parentheses, brackets, etc, from the previous line. This was fairly easy to implement, and handles many lines of Dart code correctly, or not too far off anyways.
Presumably, improving it would be difficult. If anyone is comfortable with writing parsers, my best guess is that emulating the approach taken in go-mode.el's indentation function would be the best way.
I found a description that seems to match yours, at why-isnt-this-function-or-collection-indented-enough. Maybe if we do end up taking the approach like that in go-mode.el, we could recognize where statements start and end, and whether we are in function parameters or arguments, etc, and that might get us close to detecting the scenario you describe, and indenting it correctly in the majority of cases.
Personally, for now, I simply tolerate all the discrepancies in the indentation function versus official formatter, and reformat code once my editing is valid Dart code again. Some users set Emacs to reformat automatically after each save.
Thanks for your explanation, I thought I've somehow missed some settings somewhere.
I like the way go-mode.el works, I hope dart-mode.el (and other modes as well) can work like that.
Such as the body argument of the test function, when I hit
Enter
, it gets indented by 4 spaces instead of 2, here is an exampleIt should be like this:
If I just created the function, it's OK as it's less obvious, but if go back to already created functions and tried to add something in the first line of the function body, it's really annoying, this is how it looks like:
This is the case for all function-bodies passed as arguments:
Is there any setting for this or something I can do about it? I'm writing a lot of unit test code and I'm getting a little bit frustrated because of this.