Pretty Print

A Gleam library for formatting documents like source code.

See the documentation for many examples: https://hexdocs.pm/pretty_print/

Available in hex: https://hex.pm/packages/pretty_print

Render documents to String using the least number of lines possible while trying to stay under a certain number of columns.

Works well for constraining source code to a particular width.

Examples

// The same Document may pretty print as
[ 1, 2, 3, 4 ]

// or
[ 1
, 2
, 3
, 4
]
// depending on the desired maximum columns.

// Similarly
one().two().three().four()

// may break to
one()
  .two()
  .three()
  .four()

The core concepts here are:

This is essentially some convenience wrappers around this algorithm: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.2200

Installation

This package can be installed by adding pretty_print to your rebar.config dependencies:

{deps, [
    pretty_print
]}.