-
-
Notifications
You must be signed in to change notification settings - Fork 2
Indentation and Syntax Highlighting
Emacs users expect smart indentation, and instantly.
Unfortunately indentation is not currently in an ideal state in
dart-mode
. In dart-mode
’s seven year history, it had a number of
issues with indentation and syntax highlighting, and the plan was to
fix some number of these by removing the cc-mode framework in which
these two features were implemented.
The cc-mode framework was removed from dart-mode recently. In doing so, a number of regressions will have surfaced.
The syntax highlighting seems to have gotten back to a satisfactory state. We’ve used the font-lock framework, and only a few things were overlooked, like the challenge in syntax highlighting rules that span multiple lines. Bug reports with examples will be appreciated.
The smart indentation is the harder part. On the one hand, we have
dartfmt
which will have the final say anyways, so this is not a
stopping point. But I believe the smart indentation is not up to what
an Emacs user expects, so I hope we can find a much better state.
Currently, the indentation function mostly uses a builtin function
syntax-ppss
to work out what indentation should be, based on
relative depth of parens, or previous line if there was no change in
depth.
This was easy, and this is more or less where we’ve left off with the
indentation logic. There are some additional ideas taken from the
major mode for editing python, where you can repeatedly type TAB
or
S-TAB
to indent and dedent in the way you might expect from other
editors.
If you want to return to the smart-indentation’s guess, you can press
C-c C-i
.
For us to improve indentation further, I expect we will have to
improve the logic to do some partial reverse parsing of the code.
Someone else may have an easier time at this, but for me, I would like
to get more testing in place, as well borrow an idea from cc-mode to
have feedback on what the code thinks the surrounding syntax is at
point, like cc-mode’s C-c C-s
. I had started on this some months
ago, but have not cleaned up those commits for the master branch.