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

Fix indentation function for statements continued across linebreaks #113

Open
bradyt opened this issue Jun 25, 2020 · 2 comments
Open

Fix indentation function for statements continued across linebreaks #113

bradyt opened this issue Jun 25, 2020 · 2 comments

Comments

@bradyt
Copy link
Collaborator

bradyt commented Jun 25, 2020

This seems like the biggest bug currently.

If we could get correct indentation at and around statements continued across linebreaks, I could probably code for a while without needing to use dartfmt as often.

Here's an example, taken from the dart style guide, formatted incorrectly by dart-mode.

  var bobLikesIt = isDeepFried || //
      (hasPieCrust && !vegan) || //
      containsBacon;

      bobLikes() => //
      isDeepFried || (hasPieCrust && !vegan) || containsBacon;

In other words, if you've formatted correctly at line three, then dart-mode indents incorrectly at line five, and the user is looking forward to typing out a parsable file again so that line five will be fixed.

I think this is more important than getting the amount of indentation perfect, for example, matching dartfmt exactly, or knowing when to indent by two or four spaces. The indentation above not only differs from dartfmt, but is a bit harder to read.

To illustrate what I mean by the difference between two and four not being as important, I think the following would be satisfactory if dart-mode could get it correctly:

  var bobLikesIt = isDeepFried || //
    (hasPieCrust && !vegan) || //
    containsBacon;

  bobLikes() => //
    isDeepFried || (hasPieCrust && !vegan) || containsBacon;

I think readable code is a reasonable target for dart-mode indentation function, and not as important as matching dartfmt perfectly. The user can wait for dartfmt to be applied at a convenient time. After all, dart-mode's indentation can come in handy when the file is not parsable.

The best approach would seem to be to read and understand the indentation function from go-mode.el, as it looks to be very concise and solve a similar problem.

@bradyt
Copy link
Collaborator Author

bradyt commented Jun 25, 2020

Hmm, if the previous lines were indented by dartfmt, that could motivate wanting dart-mode to be aware of when to use two versus four. At least for continued lines perhaps. But again, it might be an improvement for many cases if at least there were a two space dedent after that semi colon on line three.

@bradyt
Copy link
Collaborator Author

bradyt commented Jun 25, 2020

But at least C-x h TAB would have a nicer effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant