Better API for indent



Some language like c++ and python has advanced indent rules. The built-in indent configuration is very limited.
Some language packages like python-indent are forced to hook on “editor:newline” event.
But this approach still have issues:

  1. It can only intercept newline. Other importance keystrokes like “{” and “:” can not be intercepted.
  2. It generates superfluous event in editing history.
  3. It does not work with paste.

Can atom core provides an advanced native indent API?

Thank you!


This is a duplicate of this previous topic (among others):

We like to unify similar discussions under one topic so that people don’t have to read a bunch of different threads to get the whole story. Please continue the discussion there. I’ll be closing this topic as duplicate.



Those threads are mainly about indent behavior of some language.
In this thread, I would like discuss the API from atom core, so the package writer can implement whatever indent style they like.


What API would you propose?


Indent has three main use case:

  1. Indent on special key, like newline, bracket.
  2. Format a selection.
  3. Format on paste.

Ideally, packgae can only implement 1, and atom core uses that to support 2 and 3.

The api for 1. can be simple as TextEdit.onDidInsertChar event.

A more deiciated api is like package register some special char to writer, then writer calls onWillIndent when these char are entered. This allows user to turn off indent on paste.