Title: Theory / Unimportant / CS / Programming / oCaml / Library / Pretty Printing;
Tags: récupéré hasNotNewEffectReturnsMeaning seen_description type FromInstruction computer_to_instruction hasSeenConjDef
On every note of this deck, unless a note says otherwise:
Page: http://caml.inria.fr/resources/doc/guides/format.en.html

Instruction: Format.err_formatter
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Formatter which outputs to stderr
Language: ocaml

Name: A box
Definition: A logical pretty-printing unit
Intuition: Defines a behaviour of the pretty-printing engine to display the
material inside the box

Name: A box
Definition: A logical pretty-printing unit

Name: A break hint
Definition: a directive to the
pretty-printing engine that proposes to break the line here, if it is
necessary to properly print the rest of the material

Name: Box breaking indentation
Definition: Indentation added by a box break to the position of the box opening

Name: Hint breaking indentation
Definition: Indentation added by a newline caused by a hint break

Name: Indentation rule
Definition: the position of the box opening
Context: ocaml pretty pritting
Definition2: the box indentation rule
Conjdef: The indentation is the sum of
Definition3: the break indentation rule

Name: horizontal box
Definition: within this box, break hints do not
lead to line breaks.
Abbreviation: hbox

Name: Vertical box
Definition: within this box, every break hint lead
to a new line.
Abbreviation: vbox

Name: Vertical/horizontal box
Definition: if it is possible, the entire box
is written on a single line; otherwise, every break hint within the box
leads to a new line.
Context: oCaml pretty printing
Abbreviation: hv box

Name: Vertical or horizontal box
Definition: Either a packing or the structural vo box
Abbreviation: hov box

Instruction: print_break foo bar
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: put a hint break. Increment bar the indentation if it is used. Otherwise print foo spaces.
Language: oCaml

Instruction: open_hovbox foo
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: open a horizontal or vertical packing box with box breaking indentation foo
Language: oCaml

Name: Open or horizontal packing box
Definition: break hints are used to
cut the line when there is no more room on the line; no new
line occurs if there is enough room on the line.
Example: (---
 (----
  (---)))

Name: Open or horizontal structural box
Definition: the break hints are used to cut the line when there is no more
room on the line; in addition, break hints that can show the box
structure lead to new lines even if there is enough room on the current
line.
Example: (---
  (---
  )
 )
)

Question: During pretty printing, when you want to output a space
Answer: put a break hint, except if you really don't want one
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Kind: 4

Question: During pretty printing, when you want to output a new line
Answer: avoid it as much as possible
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Context: oCaml
Answer2: use a new_line function otherwise there is no indentation
Index: 5,6

Question: When you have finished pretty-printing
Answer: call print_newline(). It flush output and avoid printing data after the printed data
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Index: 7

Question: When you open a box
Answer: close it
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Answer2: don't hesitate
Index: 1, 2

Question: Where to put hint break ?
Answer: in as many place as possible
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Index: 3

Instruction: @[
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: open a box with indentation 0
Language: oCaml
Context: pretty printing string

Instruction: @[<bar foo>
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: open a box of kind bar with indentation foo
Language: oCaml
Context: pretty printing string

Instruction: @]
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: close a box
Language: oCaml
Context: pretty printing string

Instruction: "@ "
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: print a breakable space
Language: oCaml
Context: pretty printing string

Instruction: @,
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: put a break hint
Language: oCaml
Context: pretty printing string

Instruction: @;<foo bar>
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: put a full break hint, as with print_break foo bar
Language: oCaml
Context: pretty printing string

Instruction: @.
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: end pretty print, close all opened box and output a newline
Language: oCaml
Context: pretty printing string

Instruction: %s
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: output a string passed as argument
Language: oCaml
Context: pretty printing string

Instruction: %d
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: output a number passed as argument
Language: oCaml
Context: pretty printing string

Instruction: %a
Page: http://caml.inria.fr/resources/doc/guides/format.en.html
Effect: output a value, passed as argument with its pretty printing function
Language: oCaml
Context: pretty printing string

Name: Pretty printing formatter
Definition: A value stating where pretty printing must occur
Context: pretty printing string
Notation: ppf

Typ: formatter
Meaning: Abstract data corresponding to a pretty-printer (also called a formatter) and all its machinery
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Language: ocaml
Context: Format

Question: Which policy is followed in case of nested box ?
Answer: The innermost one
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html

Instruction: open_box bar
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: opens a new compacting pretty-printing box with offset bar
Within this box, the pretty-printer prints as much as possible material on every line.
A break hint splits the line if there is no more room on the line to print the remainder of the box.
Within this box, the pretty-printer emphasizes the box structure: a break hint also splits the line if the splitting ``moves to the left'' (i.e. the new line gets an indentation smaller than the one of the current line).
Language: oCaml

Instruction: close_box ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Closes the most recently open pretty-printing box.
Language: oCaml

Instruction: open_hbox d
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: opens a new 'vertical' pretty-printing box with offset d.
This box prints material on as many lines as break hints in the box.
Every break hint in a vertical box splits the line.
If the pretty-printer splits the line in the box, d is added to the current indentation
Language: oCaml

Instruction: open_hvbox d
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: opens a new 'horizontal/vertical' pretty-printing box with offset d.
Language: oCaml

Instruction: open_hovbox d
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: opens a new 'horizontal-or-vertical' pretty-printing box
Language: oCaml

Instruction: print_string
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: prints s in the current pretty printing box
Language: oCaml
Library: Format

Instruction: print_as foo bar
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: print bar in the current pretty-printing box. Formatted as if of length foo
Language: oCaml
Library: Format

Instruction: print_int foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: print the int foo in the current pretty-printing box
Language: oCaml
Library: Format

Instruction: print_float foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: print the float foo in the current pretty-printing box
Language: oCaml
Library: Format

Instruction: print_char foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: print the char foo in the current pretty-printing box
Language: oCaml
Library: Format

Instruction: print_bool foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: print the bool foo in the current pretty-printing box
Language: oCaml
Library: Format

Instruction: print_space ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: abbrevation for print_break 1 0
Language: oCaml
Library: Format

Instruction: print_cut ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: emits a 'cut' break hint: the pretty-printer may split the line at this point, otherwise it prints nothing.
Language: oCaml
Library: Format

Instruction: print_break foo bar
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: emits a 'full' break hint: otherwise it prints foo spaces.
If the pretty-printer splits the line, bar is added to the current indentation.
Language: oCaml
Library: Format

Instruction: force_newline ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Force a new line in the current pretty-printing box.
The pretty-printer must split the line at this point,
Language: oCaml
Assuming: Should be avoided
Library: Format

Instruction: print_if_newline ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Execute the next formatting command if the preceding line has just been split. Otherwise, ignore the next formatting command.
Language: oCaml
Assuming: Should be avoided
Library: Format

Instruction: print_flush ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: End of pretty-printing: resets the pretty-printer to initial state.
Language: oCaml
Assuming: only when mandatory
Library: Format

Instruction: print_newline ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Equivalent to Format.print_flush followed by a new line.
Language: oCaml
Library: Format

Instruction: set_margin foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: sets the right margin to foo. If required Decrease indentation limit to at most half the margin
Language: oCaml
Assuming: d at least 2
Library: Format

Instruction: get_margin ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: return the current margin
Language: oCaml
Returns: The current margin
Library: Format

Instruction: get_max_indent ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: return the current max indent
Language: oCaml
Returns: The current max indent
Library: Format

Instruction: set_max_indent foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: sets the maximum indentation limit of lines to foo (in characters): once this limit is reached, new pretty-printing boxes are rejected to the left, if they do not fit on the current line.
Ignored if foo>= current margin
Language: oCaml
Library: Format

Instruction: set_max_boxes foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Set the maximum number of pretty printing boxes simultaneously open to foo. Box more inside are replaced by ellipsis
Language: oCaml
Library: Format

Instruction: get_max_boxes ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Get the maximum number of pretty printing boxes simultaneously open
Language: oCaml
Library: Format

Instruction: over_max_boxes ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Tests if the maximum number of pretty-printing boxes allowed have already been opened.
Language: oCaml
Library: Format

Name: Tabulation box
Definition: Box where material is printed in tab
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html

Instruction: open_tbox ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Open a tabulation box
Language: oCaml
Name: Box where material is printed in tab

Instruction: close_tbox ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Close the most recently opened tabulation box
Language: oCaml

Instruction: set_tab ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Sets a tabulation marker at current insertion point.
Language: oCaml

Instruction: print_tab ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: It is equivalent to print_tbreak 0 0.
Language: oCaml

Instruction: print_tbreak foo bar
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: emits a 'full' tabulation break hint.
If not already set on a tabulation marker, the insertion point moves to the first tabulation marker on the right and the pretty-printer prints foo spaces.
If there is no next tabulation marker on the right, the pretty-printer splits the line at this point, then insertion point moves to the leftmost tabulation marker of the box.
If the pretty-printer splits the line, bar is added to the current indentation.
Language: oCaml

Instruction: set_ellipsis_text foo
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: Set the text of the ellipsis printed when too many pretty-printing boxes are open (a single dot, ., by default) to  foo
Language: oCaml

Instruction: get_ellipsis_text ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html
Effect: get the text of ellipsis
Language: oCaml

Instruction: open_tag t
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: opens the semantic tag named t.
The print_open_tag tag-printing function of the formatter is called with t as argument; then the opening tag marker for t, as given by mark_open_tag t, is written into the output device of the formatter.The print_open_tag tag-printing function of the formatter is called with mark_open_tag t, is written into the output device of the formatter.
Language: oCaml
Library: Format

Instruction: close_tag ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: closes the most recently opened semantic tag t.
The closing tag marker, as given by mark_close_tag t, is written into the output device of the formatter; then the print_close_tag tag-printing function of the formatter is called with t as argument.
Language: oCaml
Library: Format

Instruction: set_tags b
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: turns on or off the treatment of semantic tags
(default is off).
Language: oCaml
Library: Format

Instruction: set_print_tag b
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: turns on or off the tag-printing operations.
Language: oCaml
Library: Format

Instruction: set_mark_tag b
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: turns on or off the tag-marking operations.
Language: oCaml
Library: Format

Instruction: get_print_tags ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: current status of tag-printing operations.
Language: oCaml
Library: Format

Instruction: get_marks_tags ()
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: current status of tag-marking operations.
Language: oCaml
Library: Format

Instruction: set_formatter_out_channel out
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: Redirect the standard pretty-printer output to the given channel. (All the output functions of the standard formatter are set to the default output functions printing to the given channel.)
Language: oCaml
Library: Format

Instruction: set_formatter_output_functions ppf out flush
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Effect: redirects the standard pretty-printer output functions to the functions out and flush.
The out function performs all the pretty-printer string output. It is called with a string s, a start position p, and a number of characters n; it is supposed to output characters p to p + n - 1 of s.
The flush function is called whenever the pretty-printer is flushed (via conversion %!, or pretty-printing indications @? or @., or using low level functions print_flush or print_newline).
Language: oCaml
Library: Format

Instruction: get_formatter_output_functions ppf out flush
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Language: oCaml
Returns: The current output functions of the standard pretty-printer.
Library: Format

Typ: formatter_out_functions
Meaning: The set of output functions specific to a formatter:
Page: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html/
Language: ocaml
Library: Format