Pretty-Printing Projectional Editor
Growing a Structural Editor: Layout Combinators
In general, pretty printers can be used to layout any widgets in an indented layout.
Growing a Structural Editor: Layout Combinators discusses how to use pretty-printing to layout widgets in projectional editor. However, it skips the problem of cursor stability (i.e., cursor may jump unexpectedly when re-indenting the document).
ce4/virtual doc explores how to keep the cursor stable.