Ocamlformat_lib.FmtSourceFormatting combinators
Format thunks.
type sp = | Blank
| Cut@,
| Space@
| Break of Ocamlformat_stdlib.int * Ocamlformat_stdlib.int@;
Format concatenation of n elements.
Pre-compose a format thunk onto a function returning a format thunk.
Defer the evaluation of some side effects until formatting happens.
Set the margin.
Set the maximum indentation.
eval fs t runs format thunk t outputting to fs
Catch exceptions raised while formatting.
Length that will be accounted when the given string is outputted.
Break hints and format strings --------------------------------------
Format a break hint.
space_break is either a single space or a newline. See Stdlib.Format.print_space_break. Equivalement to format syntax "@ ".
cut_break is either a newline or a noop. See Stdlib.Format.print_cut. Equivalement to format syntax "@,".
force_newline force a new line in the current pretty-printing box. See Stdlib.Format.force_newline. Equivalement to format syntax "@\n".
val cbreak :
fits:
(Ocamlformat_stdlib.string
* Ocamlformat_stdlib.int
* Ocamlformat_stdlib.string) ->
breaks:
(Ocamlformat_stdlib.string
* Ocamlformat_stdlib.int
* Ocamlformat_stdlib.string) ->
tFormat a custom break.
fits = (a, b, c) formats a string a, b spaces and a string c if the line does not break.breaks = (d, e, f) formats a string d, e spaces and a string f if the line breaks.Primitive types -----------------------------------------------------
Format a char.
Format a string.
str_as a len formats a string as if it were of length len.
Primitive containers ------------------------------------------------
Format an option using provided formatter for the element.
val list_fl :
'a Ocamlformat_stdlib.list ->
(first:Ocamlformat_stdlib.bool -> last:Ocamlformat_stdlib.bool -> 'a -> t) ->
tFormat a list using provided function for the elements, which is passed the flags indicating if the element is the first or last.
val list_pn :
'a Ocamlformat_stdlib.list ->
(prev:'a Ocamlformat_stdlib.option ->
'a ->
next:'a Ocamlformat_stdlib.option ->
t) ->
tFormat a list using provided function for the elements, which is passed the previous and next elements, if any.
Format a list using the format thunk for the separators between elements.
Conditional formatting ----------------------------------------------
Conditionally format thunk.
Conditionally select between two format thunks.
Optionally format. fmt_opt (Some t) is t and fmt_opt None is noop.
Conditional on immediately following a line break -------------------
Format a string if the line has just been broken.
Format a break unless the line has just been broken.
Conditional on breaking of enclosing box ----------------------------
val fits_breaks :
?force:behavior ->
?hint:(Ocamlformat_stdlib.int * Ocamlformat_stdlib.int) ->
?level:Ocamlformat_stdlib.int ->
Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.string ->
tfits_breaks fits nspaces offset breaks prints fits if the enclosing box fits on one line, and otherwise prints breaks, which is a string that optionally follows a break hint (that is a pair (nspaces, offset) equivalent to the break hint "@;<nspaces offset>").
val fits_breaks_if :
?force:behavior ->
?hint:(Ocamlformat_stdlib.int * Ocamlformat_stdlib.int) ->
?level:Ocamlformat_stdlib.int ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.string ->
tAs fits_breaks, but conditional.
Wrapping ------------------------------------------------------------
As wrap_if, but prologue and epilogue may be arbitrary format thunks.
val wrap_if_fits_or :
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.string ->
t ->
tAs wrap_if_fits, but prologue and epilogue can be forced by the additional condition.
val wrap_fits_breaks :
?space:Ocamlformat_stdlib.bool ->
Conf.t ->
Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.string ->
t ->
tAs wrap, but if space is provided, a space is added after prologue and a space hint is added before epilogue in case the enclosing box breaks.
val wrap_fits_breaks_if :
?space:Ocamlformat_stdlib.bool ->
Conf.t ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.string ->
t ->
tAs wrap_fits_breaks, but prologue and epilogue are formatted subject to the additional condition.
Boxes ---------------------------------------------------------------
Represent boxes inside a format thunk with colored brackets. For debug purposes
Open an vbox with specified indentation.
Open an hvbox with specified indentation.
Open an hovbox with specified indentation.
Wrapping boxes ------------------------------------------------------
Wrap a format thunk with a compacting box with specified indentation.
Wrap a format thunk with a vbox with specified indentation.
Wrap a format thunk with an hvbox with specified indentation.
Wrap a format thunk with an hovbox with specified indentation.
val cbox_if :
?name:Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.int ->
t ->
tConditionally wrap a format thunk with a compacting sbox with specified indentation.
val vbox_if :
?name:Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.int ->
t ->
tConditionally wrap a format thunk with a vbox with specified indentation.
val hvbox_if :
?name:Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.int ->
t ->
tConditionally wrap a format thunk with an hvbox with specified indentation.
val hovbox_if :
?name:Ocamlformat_stdlib.string ->
Ocamlformat_stdlib.bool ->
Ocamlformat_stdlib.int ->
t ->
tConditionally wrap a format thunk with an hovbox with specified indentation.