DoxigAlpha

AutoIndentingStream

Automatically inserts indentation of written data by keeping track of the current indentation level

We introduce a new indentation scope with pushIndent/popIndent whenever we potentially want to introduce an indent after the next newline.

Indentation should only ever increment by one from one line to the next, no matter how many new indentation scopes are introduced. This is done by only realizing the indentation from the most recent scope. As an example:

while (foo) if (bar) f(x);

The body of while introduces a new indentation scope and the body of if also introduces a new indentation scope. When the newline is seen, only the indentation scope of the if is realized, and the while is not.

As comments are rendered during space rendering, we need to keep track of the appropriate indentation level for them with pushSpace/popSpace. This should be done whenever a scope that ends in a .semicolon or a .comma is introduced.

Fields of this type

Fields

#
underlying_writer:*Writer
disabled_offset:?usize
Offset into the source at which formatting has been disabled with
indent_count:usize
= 0
indent_delta:usize
indent_stack:std.array_list.Managed(StackElem)
space_stack:std.array_list.Managed(SpaceElem)
space_mode:?usize
= null
disable_indent_committing:usize
= 0
current_line_empty:bool
= true
applied_indent:usize
the most recently applied indent

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
print
Assumes that if the printed data ends with a newline, it is directly
maybeInsertNewline
Insert a newline unless the current line is blank
pushIndentOneShot
Push an indent that is automatically popped after being applied
lockOneShotIndent
Turns all one-shot indents into regular indents
pushIndentNextLine
Push an indent that should not take effect until the next line
isLineOverIndented
Checks to see if the most recent indentation exceeds the currently pushed indents
disableIndentCommitting
Disables indentation level changes during the next newlines until re-enabled.
enableSpaceMode
Sets current indentation level to be the same as that of the last pushSpace.
pushIndent
Push default indentation
forcePushIndent
Forces an indentation level to be realized.