Better API for indent


#1

Hey,

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!


#2

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.


#3

Hi,

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.


#4

What API would you propose?


#5

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.