1 USING: prettyprint io kernel help.markup help.syntax
2 prettyprint.config words hashtables math
4 IN: prettyprint.sections
7 { $var-description "The prettyprinter's current character position." } ;
10 { $var-description "The current nesting of collections being output by the prettyprinter, used to detect circularity and prevent infinite recursion." } ;
13 { $values { "?" "a boolean" } }
14 { $description "Tests if the line number limit has been reached, and thus if prettyprinting should stop." } ;
18 { $description "Outputs the current indent nesting to " { $link output-stream } "." } ;
21 { $values { "n" "the current column position" } }
22 { $description "Advances the prettyprinter by one line unless the current line is empty. If the line limit is exceeded, escapes the prettyprinter by restoring a continuation captured in " { $link do-pprint } "." } ;
25 { $description "Possible input parameter to " { $link line-break } "." } ;
28 { $description "Possible input parameter to " { $link line-break } "." } ;
30 { soft hard } related-words
33 { $values { "section" section } { "?" "a boolean" } }
34 { $contract "Tests if a section fits in the space that remains on the current line." } ;
37 { $values { "section" section } }
38 { $contract "Prints a section which fits in the current line. This should use a layout strategy maximizing line length and minimizing white space." } ;
41 { $values { "section" section } }
42 { $contract "Prints a section which spans multiple lines. This should use a layout strategy maximizing readability and minimizing line length." } ;
45 { $values { "section" section } { "?" "a boolean" } }
46 { $contract "Outputs a boolean indicating if the indent level should be increased when printing this section as a " { $link long-section } ". Default implementation outputs " { $link f } "." } ;
48 HELP: unindent-first-line?
49 { $values { "section" section } { "?" "a boolean" } }
50 { $contract "Outputs a boolean indicating if the indent level should only be increased for lines after the first line when printing this section as a " { $link long-section } ". Default implementation outputs " { $link f } "." }
51 { $notes "This is used to format " { $link colon } " sections because of the colon definition formatting convention." } ;
54 { $values { "section" section } { "?" "a boolean" } }
55 { $contract "Outputs a boolean indicating if a newline should be output after printing this section as a " { $link long-section } ". Default implementation outputs " { $link f } "." } ;
58 { $values { "section" section } { "?" "a boolean" } }
59 { $contract "Tests if a section should be output as a " { $link short-section } ". The default implementation calls " { $link section-fits? } " but this behavior can be cutomized." } ;
62 { $class-description "A piece of prettyprinter output. Instances of this class are not used directly, instead one instantiates various subclasses of this class:"
71 "Instances of this class have the following slots:"
73 { { $snippet "start" } " - the start of the section, measured in characters from the beginning of the prettyprinted output" }
74 { { $snippet "end" } " - the end of the section, measured in characters from the beginning of the prettyprinted output" }
75 { { $snippet "start-group?" } " - see " { $link start-group } }
76 { { $snippet "end-group?" } " - see " { $link end-group } }
77 { { $snippet "style" } " - character and/or paragraph styles to use when outputting this section. See " { $link "styles" } }
78 { { $snippet "overhang" } " - number of columns which must be left blank before the wrap margin for the prettyprinter to consider emitting this section as a " { $link short-section } ". Avoids lone hanging closing brackets" }
82 { $values { "length" integer } { "class" "a subclass of " { $link section } } { "section" section } }
83 { $description "Creates a new section with the given length starting from " { $link position } ", advancing " { $link position } "." } ;
86 { $values { "section" section } }
87 { $description "Increases indentation by the " { $link tab-size } " if requested by the section." } ;
90 { $values { "section" section } }
91 { $description "Decreases indentation by the " { $link tab-size } " if requested by the section." } ;
94 { $values { "section" section } }
95 { $description "Prints a line break before the section start." } ;
98 { $values { "section" section } }
99 { $description "Prints a line break after the section end if requested by the section." } ;
102 { $values { "section" section } }
103 { $description "Begins printing a long section, taking " { $link indent-section? } " and " { $link unindent-first-line? } " into account." } ;
106 { $values { "section" section } }
107 { $description "Ends printing a long section, taking " { $link indent-section? } " and " { $link newline-after? } " into account." } ;
110 { $values { "section" section } }
111 { $contract "Prints a section, performing wrapping and indentation using available formatting information." }
112 $prettyprinting-note ;
115 { $values { "type" { $link soft } " or " { $link hard } } }
116 { $description "Adds a section introducing a line break to the current block. If the block is output as a " { $link short-section } ", all breaks are ignored. Otherwise, hard breaks introduce unconditional newlines, and soft breaks introduce a newline if the position is more than half of the " { $link margin } "." }
117 $prettyprinting-note ;
120 { $class-description "A block is a section containing child sections. Blocks are introduced by calling " { $link <block } " and " { $link block> } "." } ;
123 { $values { "block" "a block section" } }
124 { $description "Outputs the block currently being constructed." }
125 $prettyprinting-note ;
128 { $values { "section" "a section" } }
129 { $description "Adds a section to the current block." }
130 $prettyprinting-note ;
133 { $description "Marks the start of a group. Sections inside a group are output on one line if possible." } ;
136 { $description "Marks the end of a group. Sections inside a group are output on one line if possible." } ;
139 { $values { "section" section } }
140 { $description "Emits whitespace between sections." }
141 $prettyprinting-note ;
143 HELP: save-end-position
144 { $values { "block" block } }
145 { $description "Save the current position as the end position of the block." } ;
147 HELP: pprint-sections
148 { $values { "block" block } { "advancer" { $quotation "( block -- )" } } }
149 { $description "Prints child sections of a block, ignoring any " { $link line-break } " sections. The " { $snippet "advancer" } " quotation is called between every pair of sections." } ;
152 { $values { "break" line-break } }
153 { $description "Prints a break section as per the policy outlined in " { $link line-break } "." } ;
156 { $values { "block" block } { "?" "a boolean" } }
157 { $description "Tests if the block has no child sections." } ;
160 { $values { "block" block } { "quot" { $quotation "( block -- )" } } }
161 { $description "If the block has child sections, calls the quotation, otherwise does nothing." } ;
164 { $values { "block" block } }
165 { $description "Begins constructing a nested block." } ;
168 { $description "Begins a plain block." } ;
171 { $values { "string" string } { "style" hashtable } { "text" "a new text section" } }
172 { $description "Creates a text section." } ;
175 { $values { "string" string } }
176 { $description "Adds a string to the current block." }
177 $prettyprinting-note ;
180 { $values { "string" string } { "style" hashtable } }
181 { $description "Adds a styled string to the current block." }
182 $prettyprinting-note ;
185 { $class-description "A " { $link block } " section which indents every line when printed as a " { $link long-section } "." } ;
188 { $values { "narrow?" "a boolean" } }
189 { $description "Begins an " { $link inset } " section. When printed as a " { $link long-section } ", the output format is determined by the " { $snippet "narrow?" } " flag. If it is " { $link f } ", then longer lines are favored, wrapping at the " { $link margin } ". Otherwise, every child section is printed on its own line." }
191 "Compare the output of printing a long quotation versus a hashtable. Quotations are printed with " { $snippet "narrow?" } " set to " { $link f } ", and hashtables are printed with " { $snippet "narrow?" } " set to " { $link t } "."
195 { $class-description "A " { $link block } " section printed on its own line if it can fit entirely on one line." } ;
198 { $description "Begins a " { $link flow } " section. " } ;
201 { $class-description "A " { $link block } " section. When printed as a " { $link long-section } ", indents every line except the first." }
202 { $notes "Colon sections are used to enclose word definitions printed by " { $link see } "." } ;
205 { $description "Begins a " { $link colon } " section." } ;
208 { $description "Adds the current block to its containing block." }
209 $prettyprinting-note ;
212 { $values { "block" block } }
213 { $description "Recursively output all children of the given block. The continuation is restored and output terminates if the line length is exceeded; this test is performed in " { $link fresh-line } "." } ;