A pretty printer.
This code is transcribed from pprint.lisp in Steel Bank Common Lisp,
which is again based on the code in CMU Common Lisp.
NEWLINE_FILL
public static final int NEWLINE_FILL
NEWLINE_LINEAR
public static final int NEWLINE_LINEAR
NEWLINE_LITERAL
public static final int NEWLINE_LITERAL
NEWLINE_MANDATORY
public static final int NEWLINE_MANDATORY
NEWLINE_MISER
public static final int NEWLINE_MISER
NEWLINE_SPACE
public static final int NEWLINE_SPACE
A non-nested ' ' gets an implicit NEWLINE_SPACE.
This is treated similarly to NEWLINE_FILL, but not quite.
buffer
public char[] buffer
Holds all the text that has been output but not yet printed.
bufferFillPointer
public int bufferFillPointer
The index into BUFFER where more text should be put.
initialBufferSize
public static int initialBufferSize
pendingBlocksCount
public int pendingBlocksCount
Number of startLogicalBlock - number of endLogicalBlock.
addIndentation
public void addIndentation(int amount,
boolean current)
clearBuffer
public void clearBuffer()
clearWordEnd
public void clearWordEnd()
close
public void close()
throws IOException
endLogicalBlock
public void endLogicalBlock()
endLogicalBlock
public void endLogicalBlock(String suffix)
enqueue
public int enqueue(int kind,
int size)
enqueueIndent
public int enqueueIndent(char kind,
int amount)
enqueueNewline
public void enqueueNewline(int kind)
forcePrettyOutput
public void forcePrettyOutput()
throws IOException
getColumnNumber
public int getColumnNumber()
Not meaningful if prettyPrintingMode > 0
.
getMiserWidth
protected int getMiserWidth()
getPrettyPrintingMode
public int getPrettyPrintingMode()
Return pretty-printing mode.
isPrettyPrinting
public boolean isPrettyPrinting()
Is pretty printing enabled?
lineAbbreviationHappened
public void lineAbbreviationHappened()
setColumnNumber
public void setColumnNumber(int column)
setIndentation
public void setIndentation(int column)
setPrettyPrinting
public void setPrettyPrinting(boolean mode)
Turn pretty printing on or off.
Equivalent to setPrettyPrintingMode(mode?1:0)
.
setPrettyPrintingMode
public void setPrettyPrintingMode(int mode)
Control pretty-printing mode.
mode
- the value 0 disables pretty-printing;
the value 1 enables ecplicit pretty-printing;
the value 2 enables pretty-printing with auto-fill, which means that
spaces are treated like enqueing NEWLINE_SPACE (essentiall a 'fill').
startLogicalBlock
public void startLogicalBlock(String prefix,
boolean perLine,
String suffix)
write
public void write(String str)
write
public void write(String str,
int start,
int count)
write
public void write(char[] str)
write
public void write(char[] str,
int start,
int count)
write
public void write(int ch)
writeBreak
public final void writeBreak(int kind)
writeWordEnd
public void writeWordEnd()
writeWordStart
public void writeWordStart()
Maybe write a word-separating space.
Specifically, write a space if the previous output
was
writeWordEnd()
. Otherwise, do nothing.