1Format(3)                        OCaml library                       Format(3)
2
3
4

NAME

6       Format - Pretty-printing.
7

Module

9       Module   Format
10

Documentation

12       Module Format
13        : sig end
14
15
16       Pretty-printing.
17
18       This  module  implements  a  pretty-printing  facility to format values
19       within Format.boxes and Format.tags combined with a set of Format.fpp .
20       The  pretty-printer  splits  lines  at  specified  Format.breaks  , and
21       indents lines according to the box structure.   Similarly,  Format.tags
22       can be used to decouple text presentation from its contents.
23
24       This  pretty-printing  facility  is implemented as an overlay on top of
25       abstract Format.formatter which provide basic output  functions.   Some
26       formatters are predefined, notably:
27
28       - Format.std_formatter outputs to stdout
29
30
31       - Format.err_formatter outputs to stderr
32
33       Most  functions in the Format module come in two variants: a short ver‐
34       sion that operates on Format.std_formatter and the generic version pre‐
35       fixed by pp_ that takes a formatter as its first argument.
36
37       More  formatters  can be created with Format.formatter_of_out_channel ,
38       Format.formatter_of_buffer , Format.formatter_of_symbolic_output_buffer
39       or using Format.formatter .
40
41
42
43
44
45
46
47   Introduction
48       For a gentle introduction to the basics of pretty-printing using Format
49       , read http://caml.inria.fr/resources/doc/guides/format.en.html.
50
51       You may consider this module as providing an extension  to  the  printf
52       facility   to   provide  automatic  line  splitting.  The  addition  of
53       pretty-printing annotations to your regular printf format strings gives
54       you fancy indentation and line breaks.  Pretty-printing annotations are
55       described below in the documentation of the function Format.fprintf .
56
57       You may also use the explicit pretty-printing box management and print‐
58       ing  functions  provided  by  this module. This style is more basic but
59       more verbose than the concise fprintf format strings.
60
61       For instance, the sequence open_box 0; print_string x =  ;  print_space
62       ();  print_int  1;  close_box  ();  print_newline  () that prints x = 1
63       within a pretty-printing box, can be abbreviated as printf @[%s@ %i@]@.
64       x = 1 , or even shorter printf @[x =@ %i@]@. 1 .
65
66       Rule of thumb for casual users of this library:
67
68       -use simple pretty-printing boxes (as obtained by open_box 0 );
69
70       -use simple break hints as obtained by print_cut () that outputs a sim‐
71       ple break hint, or by print_space () that outputs a space indicating  a
72       break hint;
73
74       -once  a  pretty-printing  box is open, display its material with basic
75       printing functions (e. g.  print_int and print_string );
76
77       -when the material for a pretty-printing box  has  been  printed,  call
78       close_box () to close the box;
79
80       -at the end of pretty-printing, flush the pretty-printer to display all
81       the remaining material, e.g. evaluate print_newline () .
82
83       The behavior of pretty-printing commands is unspecified if there is  no
84       open pretty-printing box. Each box opened by one of the open_ functions
85       below must be closed using close_box for proper formatting.  Otherwise,
86       some  of the material printed in the boxes may not be output, or may be
87       formatted incorrectly.
88
89       In case of interactive use, each phrase  is  executed  in  the  initial
90       state  of the standard pretty-printer: after each phrase execution, the
91       interactive system closes all open pretty-printing boxes,  flushes  all
92       pending text, and resets the standard pretty-printer.
93
94       Warning:  mixing calls to pretty-printing functions of this module with
95       calls to Stdlib low level output functions is error prone.
96
97       The pretty-printing functions output material that is  delayed  in  the
98       pretty-printer  queue and stacks in order to compute proper line split‐
99       ting. In contrast, basic I/O output functions write directly  in  their
100       output device. As a consequence, the output of a basic I/O function may
101       appear before the output of a pretty-printing function  that  has  been
102       called   before.   For   instance,   Stdlib.print_string   <   ;   For‐
103       mat.print_string PRETTY ; Stdlib.print_string >  ;  Format.print_string
104       TEXT ; leads to output <>PRETTYTEXT .
105
106       type formatter
107
108
109       Abstract  data corresponding to a pretty-printer (also called a format‐
110       ter) and all its machinery. See also Format.formatter .
111
112
113
114
115   Pretty-printing boxes
116       The pretty-printing engine uses the concepts of pretty-printing box and
117       break  hint  to  drive  indentation  and line splitting behavior of the
118       pretty-printer.
119
120       Each different pretty-printing box  kind  introduces  a  specific  line
121       splitting policy:
122
123
124       -within  an  horizontal  box, break hints never split the line (but the
125       line may be split in a box nested deeper),
126
127       -within a vertical box, break hints always split the line,
128
129       -within an horizontal/vertical box, if the box fits on the current line
130       then  break  hints  never  split  the line, otherwise break hint always
131       split the line,
132
133       -within a compacting box, a break hint never splits  the  line,  unless
134       there is no more room on the current line.
135
136       Note  that  line  splitting policy is box specific: the policy of a box
137       does not rule the policy of inner boxes. For instance,  if  a  vertical
138       box is nested in an horizontal box, all break hints within the vertical
139       box will split the line.
140
141       val pp_open_box : formatter -> int -> unit
142
143
144
145
146       val open_box : int -> unit
147
148
149       pp_open_box ppf d opens a new compacting pretty-printing box with  off‐
150       set d in the formatter ppf .
151
152       Within this box, the pretty-printer prints as much as possible material
153       on every line.
154
155       A break hint splits the line if there is no more room on  the  line  to
156       print the remainder of the box.
157
158       Within  this  box,  the  pretty-printer emphasizes the box structure: a
159       break hint also splits the line if the splitting ``moves to the  left''
160       (i.e. the new line gets an indentation smaller than the one of the cur‐
161       rent line).
162
163       This box is the general purpose pretty-printing box.
164
165       If the pretty-printer splits the line in the box, offset d is added  to
166       the current indentation.
167
168
169
170       val pp_close_box : formatter -> unit -> unit
171
172
173
174
175       val close_box : unit -> unit
176
177       Closes the most recently open pretty-printing box.
178
179
180
181       val pp_open_hbox : formatter -> unit -> unit
182
183
184
185
186       val open_hbox : unit -> unit
187
188
189       pp_open_hbox ppf () opens a new 'horizontal' pretty-printing box.
190
191       This box prints material on a single line.
192
193       Break  hints in a horizontal box never split the line.  (Line splitting
194       may still occur inside boxes nested deeper).
195
196
197
198       val pp_open_vbox : formatter -> int -> unit
199
200
201
202
203       val open_vbox : int -> unit
204
205
206       pp_open_vbox ppf d opens a new 'vertical' pretty-printing box with off‐
207       set d .
208
209       This box prints material on as many lines as break hints in the box.
210
211       Every break hint in a vertical box splits the line.
212
213       If  the  pretty-printer  splits  the line in the box, d is added to the
214       current indentation.
215
216
217
218       val pp_open_hvbox : formatter -> int -> unit
219
220
221
222
223       val open_hvbox : int -> unit
224
225
226       pp_open_hvbox ppf d opens a new  'horizontal/vertical'  pretty-printing
227       box with offset d .
228
229       This box behaves as an horizontal box if it fits on a single line, oth‐
230       erwise it behaves as a vertical box.
231
232       If the pretty-printer splits the line in the box, d  is  added  to  the
233       current indentation.
234
235
236
237       val pp_open_hovbox : formatter -> int -> unit
238
239
240
241
242       val open_hovbox : int -> unit
243
244
245       pp_open_hovbox ppf d opens a new 'horizontal-or-vertical' pretty-print‐
246       ing box with offset d .
247
248       This box prints material as much as possible on every line.
249
250       A break hint splits the line if there is no more room on  the  line  to
251       print the remainder of the box.
252
253       If  the  pretty-printer  splits  the line in the box, d is added to the
254       current indentation.
255
256
257
258
259   Formatting functions
260       val pp_print_string : formatter -> string -> unit
261
262
263
264
265       val print_string : string -> unit
266
267
268       pp_print_string ppf s prints s in the current pretty-printing box.
269
270
271
272       val pp_print_as : formatter -> int -> string -> unit
273
274
275
276
277       val print_as : int -> string -> unit
278
279
280       pp_print_as ppf len s prints s in the current pretty-printing box.  The
281       pretty-printer formats s as if it were of length len .
282
283
284
285       val pp_print_int : formatter -> int -> unit
286
287
288
289
290       val print_int : int -> unit
291
292       Print an integer in the current pretty-printing box.
293
294
295
296       val pp_print_float : formatter -> float -> unit
297
298
299
300
301       val print_float : float -> unit
302
303       Print a floating point number in the current pretty-printing box.
304
305
306
307       val pp_print_char : formatter -> char -> unit
308
309
310
311
312       val print_char : char -> unit
313
314       Print a character in the current pretty-printing box.
315
316
317
318       val pp_print_bool : formatter -> bool -> unit
319
320
321
322
323       val print_bool : bool -> unit
324
325       Print a boolean in the current pretty-printing box.
326
327
328
329
330   Break hints
331       A  'break  hint' tells the pretty-printer to output some space or split
332       the line whichever way is more appropriate to the current pretty-print‐
333       ing box splitting rules.
334
335       Break  hints  are  used to separate printing items and are mandatory to
336       let the pretty-printer correctly split lines and indent items.
337
338       Simple break hints are:
339
340       -the 'space': output a space or split the line if appropriate,
341
342       -the 'cut': split the line if appropriate.
343
344       Note: the notions of space and line  splitting  are  abstract  for  the
345       pretty-printing engine, since those notions can be completely redefined
346       by the programmer.  However, in  the  pretty-printer  default  setting,
347       ``output  a space'' simply means printing a space character (ASCII code
348       32) and ``split the line'' means printing a  newline  character  (ASCII
349       code 10).
350
351       val pp_print_space : formatter -> unit -> unit
352
353
354
355
356       val print_space : unit -> unit
357
358
359       pp_print_space  ppf  ()  emits a 'space' break hint: the pretty-printer
360       may split the line at this point, otherwise it prints one space.
361
362
363       pp_print_space ppf () is equivalent to pp_print_break ppf 1 0 .
364
365
366
367       val pp_print_cut : formatter -> unit -> unit
368
369
370
371
372       val print_cut : unit -> unit
373
374
375       pp_print_cut ppf () emits a 'cut' break hint:  the  pretty-printer  may
376       split the line at this point, otherwise it prints nothing.
377
378
379       pp_print_cut ppf () is equivalent to pp_print_break ppf 0 0 .
380
381
382
383       val pp_print_break : formatter -> int -> int -> unit
384
385
386
387
388       val print_break : int -> int -> unit
389
390
391       pp_print_break  ppf  nspaces  offset  emits  a  'full'  break hint: the
392       pretty-printer may split the line at this point,  otherwise  it  prints
393       nspaces spaces.
394
395       If  the  pretty-printer splits the line, offset is added to the current
396       indentation.
397
398
399
400       val pp_print_custom_break : formatter -> fits:string * int * string  ->
401       breaks:string * int * string -> unit
402
403
404       pp_print_custom_break ppf ~fits:(s1, n, s2) ~breaks:(s3, m, s4) emits a
405       custom break hint: the pretty-printer may split the line at this point.
406
407       If it does not split the line, then the s1 is emitted, then  n  spaces,
408       then s2 .
409
410       If  it  splits  the  line,  then it emits the s3 string, then an indent
411       (according to the box rules), then an offset of m spaces, then  the  s4
412       string.
413
414       While  n  and m are handled by formatter_out_functions.out_indent , the
415       strings will be handled by  formatter_out_functions.out_string  .  This
416       allows  for a custom formatter that handles indentation distinctly, for
417       example, outputs <br/> tags or &nbsp; entities.
418
419       The custom break  is  useful  if  you  want  to  change  which  visible
420       (non-whitespace)  characters  are printed in case of break or no break.
421       For example, when printing a list [a; b; c] , you might want to  add  a
422       trailing semicolon when it is printed vertically:
423
424
425       [ a; b; c; ]
426
427       You   can   do   this   as   follows:   printf   @[<v   0>[@;<0  2>@[<v
428       0>a;@,b;@,c@]%t]@]@\n   (pp_print_custom_break   ~fits:("",    0,     )
429       ~breaks:(";", 0,  ))
430
431
432
433       Since 4.08.0
434
435
436
437       val pp_force_newline : formatter -> unit -> unit
438
439
440
441
442       val force_newline : unit -> unit
443
444       Force a new line in the current pretty-printing box.
445
446       The pretty-printer must split the line at this point,
447
448       Not  the normal way of pretty-printing, since imperative line splitting
449       may interfere with current line  counters  and  box  size  calculation.
450       Using break hints within an enclosing vertical box is a better alterna‐
451       tive.
452
453
454
455       val pp_print_if_newline : formatter -> unit -> unit
456
457
458
459
460       val print_if_newline : unit -> unit
461
462       Execute the next formatting command if the preceding line has just been
463       split. Otherwise, ignore the next formatting command.
464
465
466
467
468   Pretty-printing termination
469       val pp_print_flush : formatter -> unit -> unit
470
471
472
473
474       val print_flush : unit -> unit
475
476       End of pretty-printing: resets the pretty-printer to initial state.
477
478       All open pretty-printing boxes are closed, all pending text is printed.
479       In addition, the pretty-printer low level output device is  flushed  to
480       ensure that all pending text is really displayed.
481
482       Note:  never  use print_flush in the normal course of a pretty-printing
483       routine, since the pretty-printer uses a complex buffering machinery to
484       properly  indent  the output; manually flushing those buffers at random
485       would conflict with the pretty-printer strategy and result to poor ren‐
486       dering.
487
488       Only consider using print_flush when displaying all pending material is
489       mandatory (for instance in case of interactive use when  you  want  the
490       user  to  read  some  text) and when resetting the pretty-printer state
491       will not disturb further pretty-printing.
492
493       Warning: If the output device of the pretty-printer is an output  chan‐
494       nel,  repeated  calls  to  print_flush means repeated calls to flush to
495       flush the out channel;  these  explicit  flush  calls  could  foil  the
496       buffering  strategy  of  output  channels and could dramatically impact
497       efficiency.
498
499
500
501       val pp_print_newline : formatter -> unit -> unit
502
503
504
505
506       val print_newline : unit -> unit
507
508       End of pretty-printing: resets the pretty-printer to initial state.
509
510       All open pretty-printing boxes are closed, all pending text is printed.
511
512       Equivalent to Format.print_flush followed by a new  line.   See  corre‐
513       sponding words of caution for Format.print_flush .
514
515       Note:  this  is  not the normal way to output a new line; the preferred
516       method is using break hints within a vertical pretty-printing box.
517
518
519
520
521   Margin
522       val pp_set_margin : formatter -> int -> unit
523
524
525
526
527       val set_margin : int -> unit
528
529
530       pp_set_margin ppf d sets the right margin to  d  (in  characters):  the
531       pretty-printer splits lines that overflow the right margin according to
532       the break hints given.  Nothing happens if d is smaller than 2.   If  d
533       is  too  large, the right margin is set to the maximum admissible value
534       (which is greater than 10 ^ 9 ).  If d is less than the current maximum
535       indentation  limit,  the  maximum  indentation limit is decreased while
536       trying to preserve a minimal ratio max_indent/margin>=50% and if possi‐
537       ble the current difference margin - max_indent .
538
539       See also Format.pp_set_geometry .
540
541
542
543       val pp_get_margin : formatter -> unit -> int
544
545
546
547
548       val get_margin : unit -> int
549
550       Returns the position of the right margin.
551
552
553
554
555   Maximum indentation limit
556       val pp_set_max_indent : formatter -> int -> unit
557
558
559
560
561       val set_max_indent : int -> unit
562
563
564       pp_set_max_indent  ppf d sets the maximum indentation limit of lines to
565       d (in characters): once this  limit  is  reached,  new  pretty-printing
566       boxes  are rejected to the left, unless the enclosing box fully fits on
567       the current line.  As an illustration, set_margin 10; set_max_indent 5;
568       printf  @[123456@[7@]89A@]@.  yields 123456 789A because the nested box
569       @[7@] is opened after the maximum indentation limit (  7>5  )  and  its
570       parent  box  does  not  fit on the current line.  Either decreasing the
571       length  of  the  parent  box  to  make  it  fit  on  a   line:   printf
572       @[123456@[7@]89@]@.   or opening an intermediary box before the maximum
573       indentation   limit   which   fits   on   the   current   line   printf
574       @[123@[456@[7@]89@]A@]@.  avoids the rejection to the left of the inner
575       boxes and print respectively 123456789 and 123456789A .  Note also that
576       vertical  boxes  never  fit  on  a line whereas horizontal boxes always
577       fully fit on the current line.
578
579       Nothing happens if d is smaller than 2.
580
581       If d is too large, the limit is set to  the  maximum  admissible  value
582       (which is greater than 10 ^ 9 ).
583
584       If  d  is  greater or equal than the current margin, it is ignored, and
585       the current maximum indentation limit is kept.
586
587       See also Format.pp_set_geometry .
588
589
590
591       val pp_get_max_indent : formatter -> unit -> int
592
593
594
595
596       val get_max_indent : unit -> int
597
598       Return the maximum indentation limit (in characters).
599
600
601
602
603   Geometry
604       Geometric functions can be used to manipulate simultaneously  the  cou‐
605       pled variables, margin and maxixum indentation limit.
606
607       type geometry = {
608        max_indent : int ;
609        margin : int ;
610        }
611
612
613
614
615
616       val check_geometry : geometry -> bool
617
618       Check if the formatter geometry is valid: 1 < max_indent < margin
619
620
621
622
623       val pp_set_geometry : formatter -> max_indent:int -> margin:int -> unit
624
625
626
627
628       val set_geometry : max_indent:int -> margin:int -> unit
629
630
631
632
633       val pp_safe_set_geometry : formatter -> max_indent:int -> margin:int ->
634       unit
635
636
637
638
639       val safe_set_geometry : max_indent:int -> margin:int -> unit
640
641
642       pp_set_geometry ppf ~max_indent ~margin sets both the margin and  maxi‐
643       mum indentation limit for ppf .
644
645       When  1 < max_indent < margin , pp_set_geometry ppf ~max_indent ~margin
646       is  equivalent  to  pp_set_margin  ppf  margin;  pp_set_max_indent  ppf
647       max_indent  ;  and  avoids  the  subtly incorrect pp_set_max_indent ppf
648       max_indent; pp_set_margin ppf margin ;
649
650       Outside of this domain,  pp_set_geometry  raises  an  invalid  argument
651       exception whereas pp_safe_set_geometry does nothing.
652
653
654       Since 4.08.0
655
656
657
658       val pp_get_geometry : formatter -> unit -> geometry
659
660
661
662
663       val get_geometry : unit -> geometry
664
665       Return the current geometry of the formatter
666
667
668       Since 4.08.0
669
670
671
672
673   Maximum formatting depth
674       The  maximum  formatting depth is the maximum number of pretty-printing
675       boxes simultaneously open.
676
677       Material inside boxes nested deeper is printed  as  an  ellipsis  (more
678       precisely as the text returned by Format.get_ellipsis_text () ).
679
680       val pp_set_max_boxes : formatter -> int -> unit
681
682
683
684
685       val set_max_boxes : int -> unit
686
687
688       pp_set_max_boxes  ppf  max  sets  the maximum number of pretty-printing
689       boxes simultaneously open.
690
691       Material inside boxes nested deeper is printed  as  an  ellipsis  (more
692       precisely as the text returned by Format.get_ellipsis_text () ).
693
694       Nothing happens if max is smaller than 2.
695
696
697
698       val pp_get_max_boxes : formatter -> unit -> int
699
700
701
702
703       val get_max_boxes : unit -> int
704
705       Returns  the  maximum  number  of  pretty-printing boxes allowed before
706       ellipsis.
707
708
709
710       val pp_over_max_boxes : formatter -> unit -> bool
711
712
713
714
715       val over_max_boxes : unit -> bool
716
717       Tests if the maximum  number  of  pretty-printing  boxes  allowed  have
718       already been opened.
719
720
721
722
723   Tabulation boxes
724       A  tabulation  box prints material on lines divided into cells of fixed
725       length. A tabulation box provides a simple way to display vertical col‐
726       umns of left adjusted text.
727
728       This  box  features command set_tab to define cell boundaries, and com‐
729       mand print_tab to move from cell to cell and split the line when  there
730       is no more cells to print on the line.
731
732       Note:  printing  within  tabulation  box is line directed, so arbitrary
733       line splitting inside a tabulation box leads to  poor  rendering.  Yet,
734       controlled  use  of  tabulation boxes allows simple printing of columns
735       within module Format .
736
737       val pp_open_tbox : formatter -> unit -> unit
738
739
740
741
742       val open_tbox : unit -> unit
743
744
745       open_tbox () opens a new tabulation box.
746
747       This box prints lines separated into cells of fixed width.
748
749       Inside a tabulation box, special tabulation markers defines  points  of
750       interest  on the line (for instance to delimit cell boundaries).  Func‐
751       tion Format.set_tab sets a tabulation marker at insertion point.
752
753       A tabulation box features specific tabulation breaks to  move  to  next
754       tabulation  marker  or  split  the  line.  Function Format.print_tbreak
755       prints a tabulation break.
756
757
758
759       val pp_close_tbox : formatter -> unit -> unit
760
761
762
763
764       val close_tbox : unit -> unit
765
766       Closes the most recently opened tabulation box.
767
768
769
770       val pp_set_tab : formatter -> unit -> unit
771
772
773
774
775       val set_tab : unit -> unit
776
777       Sets a tabulation marker at current insertion point.
778
779
780
781       val pp_print_tab : formatter -> unit -> unit
782
783
784
785
786       val print_tab : unit -> unit
787
788
789       print_tab () emits a 'next' tabulation break hint: if not  already  set
790       on  a tabulation marker, the insertion point moves to the first tabula‐
791       tion marker on the right, or the pretty-printer  splits  the  line  and
792       insertion point moves to the leftmost tabulation marker.
793
794       It is equivalent to print_tbreak 0 0 .
795
796
797
798       val pp_print_tbreak : formatter -> int -> int -> unit
799
800
801
802
803       val print_tbreak : int -> int -> unit
804
805
806       print_tbreak nspaces offset emits a 'full' tabulation break hint.
807
808       If not already set on a tabulation marker, the insertion point moves to
809       the first tabulation marker on the right and the pretty-printer  prints
810       nspaces spaces.
811
812       If  there is no next tabulation marker on the right, the pretty-printer
813       splits the line at this point, then insertion point moves to the  left‐
814       most tabulation marker of the box.
815
816       If  the  pretty-printer splits the line, offset is added to the current
817       indentation.
818
819
820
821
822   Ellipsis
823       val pp_set_ellipsis_text : formatter -> string -> unit
824
825
826
827
828       val set_ellipsis_text : string -> unit
829
830       Set the text of the ellipsis  printed  when  too  many  pretty-printing
831       boxes are open (a single dot, .  , by default).
832
833
834
835       val pp_get_ellipsis_text : formatter -> unit -> string
836
837
838
839
840       val get_ellipsis_text : unit -> string
841
842       Return the text of the ellipsis.
843
844
845
846
847   Semantic tags
848       type stag = ..
849
850
851       Semantic  tags (or simply tags) are user's defined annotations to asso‐
852       ciate user's specific operations to printed entities.
853
854       Common usage of semantic tags is text decoration to get  specific  font
855       or text size rendering for a display device, or marking delimitation of
856       entities (e.g. HTML or TeX  elements  or  terminal  escape  sequences).
857       More  sophisticated usage of semantic tags could handle dynamic modifi‐
858       cation of the pretty-printer behavior to properly  print  the  material
859       within some specific tags.  For instance, we can define an RGB tag like
860       so: type stag += RGB of {r:int;g:int;b:int}
861
862       In order to properly delimit printed entities, a semantic tag  must  be
863       opened  before and closed after the entity. Semantic tags must be prop‐
864       erly  nested  like  parentheses  using  Format.pp_open_stag  and   For‐
865       mat.pp_close_stag .
866
867       Tag  specific  operations  occur any time a tag is opened or closed, At
868       each occurrence, two kinds of operations are performed tag-marking  and
869       tag-printing:
870
871       -The  tag-marking  operation  is the simpler tag specific operation: it
872       simply writes a tag specific string into the output device of the  for‐
873       matter. Tag-marking does not interfere with line-splitting computation.
874
875       -The  tag-printing  operation  is the more involved tag specific opera‐
876       tion: it can print arbitrary material to the formatter. Tag-printing is
877       tightly linked to the current pretty-printer operations.
878
879       Roughly  speaking, tag-marking is commonly used to get a better render‐
880       ing of texts in the rendering device, while  tag-printing  allows  fine
881       tuning  of  printing  routines  to  print  the  same entity differently
882       according to the semantic tags (i.e. print additional material or  even
883       omit parts of the output).
884
885       More  precisely:  when a semantic tag is opened or closed then both and
886       successive 'tag-printing' and 'tag-marking' operations occur:
887
888       -Tag-printing a semantic tag means calling the formatter specific func‐
889       tion  print_open_stag  (resp.   print_close_stag ) with the name of the
890       tag as argument: that tag-printing function can then print any  regular
891       material  to  the formatter (so that this material is enqueued as usual
892       in the formatter queue for further line splitting computation).
893
894       -Tag-marking a semantic tag means calling the formatter specific  func‐
895       tion  mark_open_stag (resp.  mark_close_stag ) with the name of the tag
896       as argument: that tag-marking function can then return the 'tag-opening
897       marker'  (resp. `tag-closing marker') for direct output into the output
898       device of the formatter.
899
900       Being written directly into the output device of the formatter,  seman‐
901       tic tag marker strings are not considered as part of the printing mate‐
902       rial that drives line splitting (in other  words,  the  length  of  the
903       strings  corresponding  to  tag  markers is considered as zero for line
904       splitting).
905
906       Thus,  semantic  tag  handling  is  in  some   sense   transparent   to
907       pretty-printing and does not interfere with usual indentation. Hence, a
908       single pretty-printing routine can output both simple 'verbatim'  mate‐
909       rial  or richer decorated output depending on the treatment of tags. By
910       default, tags are not active, hence the output is  not  decorated  with
911       tag  information.  Once  set_tags  is  set to true , the pretty-printer
912       engine honors tags and decorates the output accordingly.
913
914       Default tag-marking functions  behave  the  HTML  way:  Format.tag  are
915       enclosed  in  "<"  and ">" while other tags are ignored; hence, opening
916       marker for tag string t is <t> and closing marker is </t> .
917
918       Default tag-printing functions just do nothing.
919
920       Tag-marking and tag-printing functions are user definable  and  can  be
921       set by calling Format.set_formatter_stag_functions .
922
923       Semantic  tag  operations  may  be set on or off with Format.set_tags .
924       Tag-marking operations may be set on or off with Format.set_mark_tags .
925       Tag-printing operations may be set on or off with Format.set_print_tags
926       .
927
928
929       type tag = string
930
931
932
933
934       type stag +=
935        | String_tag of tag  (* String_tag s is a string tag s .  String  tags
936       can  be  inserted either by explicitly using the constructor String_tag
937       or by using the dedicated format syntax @{<s> ... @} .
938        *)
939
940
941
942
943
944       val pp_open_stag : formatter -> stag -> unit
945
946
947
948
949       val open_stag : stag -> unit
950
951
952       pp_open_stag ppf t opens the semantic tag named t .
953
954       The print_open_stag tag-printing function of the  formatter  is  called
955       with  t  as  argument;  then the opening tag marker for t , as given by
956       mark_open_stag t , is written into the output device of the formatter.
957
958
959
960       val pp_close_stag : formatter -> unit -> unit
961
962
963
964
965       val close_stag : unit -> unit
966
967
968       pp_close_stag ppf () closes the most recently opened semantic tag t .
969
970       The closing tag marker, as given by mark_close_stag t , is written into
971       the   output   device  of  the  formatter;  then  the  print_close_stag
972       tag-printing function of the formatter is called with t as argument.
973
974
975
976       val pp_set_tags : formatter -> bool -> unit
977
978
979
980
981       val set_tags : bool -> unit
982
983
984       pp_set_tags ppf b turns on  or  off  the  treatment  of  semantic  tags
985       (default is off).
986
987
988
989       val pp_set_print_tags : formatter -> bool -> unit
990
991
992
993
994       val set_print_tags : bool -> unit
995
996
997       pp_set_print_tags ppf b turns on or off the tag-printing operations.
998
999
1000
1001       val pp_set_mark_tags : formatter -> bool -> unit
1002
1003
1004
1005
1006       val set_mark_tags : bool -> unit
1007
1008
1009       pp_set_mark_tags ppf b turns on or off the tag-marking operations.
1010
1011
1012
1013       val pp_get_print_tags : formatter -> unit -> bool
1014
1015
1016
1017
1018       val get_print_tags : unit -> bool
1019
1020       Return the current status of tag-printing operations.
1021
1022
1023
1024       val pp_get_mark_tags : formatter -> unit -> bool
1025
1026
1027
1028
1029       val get_mark_tags : unit -> bool
1030
1031       Return the current status of tag-marking operations.
1032
1033
1034
1035       val pp_set_formatter_out_channel : formatter -> out_channel -> unit
1036
1037
1038   Redirecting the standard formatter output
1039       val set_formatter_out_channel : out_channel -> unit
1040
1041       Redirect the standard pretty-printer output to the given channel.  (All
1042       the output functions of the standard formatter are set to  the  default
1043       output functions printing to the given channel.)
1044
1045
1046       set_formatter_out_channel   is   equivalent   to  Format.pp_set_format‐
1047       ter_out_channel std_formatter .
1048
1049
1050
1051       val pp_set_formatter_output_functions : formatter -> (string -> int  ->
1052       int -> unit) -> (unit -> unit) -> unit
1053
1054
1055
1056
1057       val  set_formatter_output_functions : (string -> int -> int -> unit) ->
1058       (unit -> unit) -> unit
1059
1060
1061       pp_set_formatter_output_functions ppf out flush redirects the  standard
1062       pretty-printer output functions to the functions out and flush .
1063
1064       The  out function performs all the pretty-printer string output.  It is
1065       called with a string s , a start position p , and a number  of  charac‐
1066       ters n ; it is supposed to output characters p to p + n - 1 of s .
1067
1068       The  flush  function  is  called whenever the pretty-printer is flushed
1069       (via conversion %!  , or pretty-printing indications @?  or  @.   ,  or
1070       using low level functions print_flush or print_newline ).
1071
1072
1073
1074       val pp_get_formatter_output_functions : formatter -> unit -> (string ->
1075       int -> int -> unit) * (unit -> unit)
1076
1077
1078
1079
1080       val get_formatter_output_functions : unit -> (string -> int ->  int  ->
1081       unit) * (unit -> unit)
1082
1083       Return the current output functions of the standard pretty-printer.
1084
1085
1086
1087
1088   Redefining formatter output
1089       The  Format  module  is versatile enough to let you completely redefine
1090       the meaning of pretty-printing output: you may provide your  own  func‐
1091       tions  to  define  how  to handle indentation, line splitting, and even
1092       printing of all the characters that have to be printed!
1093
1094   Redefining output functions
1095       type formatter_out_functions = {
1096        out_string : string -> int -> int -> unit ;
1097        out_flush : unit -> unit ;
1098        out_newline : unit -> unit ;
1099        out_spaces : int -> unit ;
1100        out_indent : int -> unit ;
1101        }
1102
1103
1104       The set of output functions specific to a formatter:
1105
1106       -the out_string function performs all the pretty-printer string output.
1107       It  is  called  with  a string s , a start position p , and a number of
1108       characters n ; it is supposed to output characters p to p + n - 1 of  s
1109       .
1110
1111       -the out_flush function flushes the pretty-printer output device.
1112
1113       -  out_newline  is  called  to  open a new line when the pretty-printer
1114       splits the line.
1115
1116       -the out_spaces function outputs spaces when a break hint leads to spa‐
1117       ces  instead of a line split. It is called with the number of spaces to
1118       output.
1119
1120       -the  out_indent  function  performs  new  line  indentation  when  the
1121       pretty-printer splits the line. It is called with the indentation value
1122       of the new line.
1123
1124       By default:
1125
1126       -fields out_string and out_flush  are  output  device  specific;  (e.g.
1127       output_string  and  flush  for a out_channel device, or Buffer.add_sub‐
1128       string and ignore for a Buffer.t output device),
1129
1130       -field out_newline is equivalent to out_string \n 0 1 ;
1131
1132       -fields  out_spaces  and  out_indent  are  equivalent   to   out_string
1133       (String.make n ' ') 0 n .
1134
1135
1136
1137       Since 4.01.0
1138
1139
1140
1141       val  pp_set_formatter_out_functions  : formatter -> formatter_out_func‐
1142       tions -> unit
1143
1144
1145
1146
1147       val set_formatter_out_functions : formatter_out_functions -> unit
1148
1149
1150       pp_set_formatter_out_functions ppf out_funs Set all the  pretty-printer
1151       output functions of ppf to those of argument out_funs ,
1152
1153       This way, you can change the meaning of indentation (which can be some‐
1154       thing else than just printing space characters) and the meaning of  new
1155       lines opening (which can be connected to any other action needed by the
1156       application at hand).
1157
1158       Reasonable  defaults  for  functions  out_spaces  and  out_newline  are
1159       respectively   out_funs.out_string   (String.make   n  '  ')  0  n  and
1160       out_funs.out_string \n 0 1 .
1161
1162
1163       Since 4.01.0
1164
1165
1166
1167       val pp_get_formatter_out_functions  :  formatter  ->  unit  ->  format‐
1168       ter_out_functions
1169
1170
1171
1172
1173       val get_formatter_out_functions : unit -> formatter_out_functions
1174
1175       Return  the  current  output functions of the pretty-printer, including
1176       line splitting and indentation functions. Useful to record the  current
1177       setting and restore it afterwards.
1178
1179
1180       Since 4.01.0
1181
1182
1183
1184
1185   Redefining semantic tag operations
1186       type formatter_stag_functions = {
1187        mark_open_stag : stag -> string ;
1188        mark_close_stag : stag -> string ;
1189        print_open_stag : stag -> unit ;
1190        print_close_stag : stag -> unit ;
1191        }
1192
1193
1194       The  semantic tag handling functions specific to a formatter: mark ver‐
1195       sions are the 'tag-marking' functions that associate a string marker to
1196       a tag in order for the pretty-printing engine to write those markers as
1197       0 length tokens in the output device of the formatter.  print  versions
1198       are the 'tag-printing' functions that can perform regular printing when
1199       a tag is closed or opened.
1200
1201
1202
1203       val pp_set_formatter_stag_functions : formatter -> formatter_stag_func‐
1204       tions -> unit
1205
1206
1207
1208
1209       val set_formatter_stag_functions : formatter_stag_functions -> unit
1210
1211
1212       pp_set_formatter_stag_functions  ppf  tag_funs  changes  the meaning of
1213       opening and closing semantic tag operations to  use  the  functions  in
1214       tag_funs when printing on ppf .
1215
1216       When opening a semantic tag with name t , the string t is passed to the
1217       opening tag-marking function (the mark_open_stag field  of  the  record
1218       tag_funs ), that must return the opening tag marker for that name. When
1219       the next call to close_stag () happens, the semantic tag name t is sent
1220       back  to the closing tag-marking function (the mark_close_stag field of
1221       record tag_funs ), that must return a closing tag marker for that name.
1222
1223       The print_ field of the record contains the tag-printing functions that
1224       are called at tag opening and tag closing time, to output regular mate‐
1225       rial in the pretty-printer queue.
1226
1227
1228
1229       val pp_get_formatter_stag_functions :  formatter  ->  unit  ->  format‐
1230       ter_stag_functions
1231
1232
1233
1234
1235       val get_formatter_stag_functions : unit -> formatter_stag_functions
1236
1237       Return  the  current  semantic  tag operation functions of the standard
1238       pretty-printer.
1239
1240
1241
1242
1243   Defining formatters
1244       Defining new formatters permits unrelated output of material in  paral‐
1245       lel  on  several output devices.  All the parameters of a formatter are
1246       local to the formatter: right margin, maximum indentation limit,  maxi‐
1247       mum  number of pretty-printing boxes simultaneously open, ellipsis, and
1248       so on, are specific to each formatter and may be fixed independently.
1249
1250       For instance, given a Buffer.t buffer b , Format.formatter_of_buffer  b
1251       returns  a  new  formatter  using buffer b as its output device.  Simi‐
1252       larly,  given  a  out_channel  output  channel  oc   ,   Format.format‐
1253       ter_of_out_channel  oc  returns a new formatter using channel oc as its
1254       output device.
1255
1256       Alternatively, given out_funs , a complete set of output functions  for
1257       a formatter, then Format.formatter_of_out_functions out_funs computes a
1258       new formatter using those functions for output.
1259
1260       val formatter_of_out_channel : out_channel -> formatter
1261
1262
1263       formatter_of_out_channel oc returns a new formatter writing to the cor‐
1264       responding output channel oc .
1265
1266
1267
1268       val std_formatter : formatter
1269
1270       The standard formatter to write to standard output.
1271
1272       It is defined as Format.formatter_of_out_channel stdout .
1273
1274
1275
1276       val err_formatter : formatter
1277
1278       A formatter to write to standard error.
1279
1280       It is defined as Format.formatter_of_out_channel stderr .
1281
1282
1283
1284       val formatter_of_buffer : Buffer.t -> formatter
1285
1286
1287       formatter_of_buffer  b returns a new formatter writing to buffer b . At
1288       the end of pretty-printing, the formatter must be  flushed  using  For‐
1289       mat.pp_print_flush  or Format.pp_print_newline , to print all the pend‐
1290       ing material into the buffer.
1291
1292
1293
1294       val stdbuf : Buffer.t
1295
1296       The string buffer in which str_formatter writes.
1297
1298
1299
1300       val str_formatter : formatter
1301
1302       A formatter to output to the Format.stdbuf string buffer.
1303
1304
1305       str_formatter is defined as Format.formatter_of_buffer Format.stdbuf .
1306
1307
1308
1309       val flush_str_formatter : unit -> string
1310
1311       Returns the material printed with str_formatter , flushes the formatter
1312       and resets the corresponding buffer.
1313
1314
1315
1316       val  make_formatter  : (string -> int -> int -> unit) -> (unit -> unit)
1317       -> formatter
1318
1319
1320       make_formatter out flush returns a  new  formatter  that  outputs  with
1321       function out , and flushes with function flush .
1322
1323       For instance, make_formatter (Stdlib.output oc) (fun () -> Stdlib.flush
1324       oc) returns a formatter to the out_channel oc .
1325
1326
1327
1328       val formatter_of_out_functions : formatter_out_functions -> formatter
1329
1330
1331       formatter_of_out_functions out_funs returns a new formatter that writes
1332       with the set of output functions out_funs .
1333
1334       See  definition  of type Format.formatter_out_functions for the meaning
1335       of argument out_funs .
1336
1337
1338       Since 4.06.0
1339
1340
1341
1342
1343   Symbolic pretty-printing
1344       Symbolic pretty-printing is pretty-printing using a symbolic formatter,
1345       i.e. a formatter that outputs symbolic pretty-printing items.
1346
1347       When using a symbolic formatter, all regular pretty-printing activities
1348       occur but output material is symbolic and stored in a buffer of  output
1349       items.   At  the  end  of  pretty-printing,  flushing the output buffer
1350       allows post-processing of symbolic output before performing  low  level
1351       output operations.
1352
1353       In practice, first define a symbolic output buffer b using:
1354
1355       -  let  sob  = make_symbolic_output_buffer () .  Then define a symbolic
1356       formatter with:
1357
1358       - let ppf = formatter_of_symbolic_output_buffer sob
1359
1360       Use symbolic formatter ppf as usual, and retrieve symbolic items at end
1361       of pretty-printing by flushing symbolic output buffer sob with:
1362
1363       - flush_symbolic_output_buffer sob .
1364
1365
1366       type symbolic_output_item =
1367        | Output_flush  (* symbolic flush command
1368        *)
1369        | Output_newline  (* symbolic newline command
1370        *)
1371        | Output_string of string
1372         (* Output_string s : symbolic output for string s
1373
1374        *)
1375        | Output_spaces of int
1376         (* Output_spaces n : symbolic command to output n spaces
1377        *)
1378        | Output_indent of int
1379         (* Output_indent i : symbolic indentation of size i
1380
1381        *)
1382
1383
1384       Items produced by symbolic pretty-printers
1385
1386
1387       Since 4.06.0
1388
1389
1390       type symbolic_output_buffer
1391
1392
1393       The output buffer of a symbolic pretty-printer.
1394
1395
1396       Since 4.06.0
1397
1398
1399
1400       val make_symbolic_output_buffer : unit -> symbolic_output_buffer
1401
1402
1403       make_symbolic_output_buffer () returns a fresh buffer for symbolic out‐
1404       put.
1405
1406
1407       Since 4.06.0
1408
1409
1410
1411       val clear_symbolic_output_buffer : symbolic_output_buffer -> unit
1412
1413
1414       clear_symbolic_output_buffer sob resets buffer sob .
1415
1416
1417       Since 4.06.0
1418
1419
1420
1421       val  get_symbolic_output_buffer  :   symbolic_output_buffer   ->   sym‐
1422       bolic_output_item list
1423
1424
1425       get_symbolic_output_buffer sob returns the contents of buffer sob .
1426
1427
1428       Since 4.06.0
1429
1430
1431
1432       val   flush_symbolic_output_buffer  :  symbolic_output_buffer  ->  sym‐
1433       bolic_output_item list
1434
1435
1436       flush_symbolic_output_buffer sob returns the contents of buffer sob and
1437       resets  buffer sob .  flush_symbolic_output_buffer sob is equivalent to
1438       let  items  =  get_symbolic_output_buffer  sob  in  clear_symbolic_out‐
1439       put_buffer sob; items
1440
1441
1442
1443       Since 4.06.0
1444
1445
1446
1447       val  add_symbolic_output_item : symbolic_output_buffer -> symbolic_out‐
1448       put_item -> unit
1449
1450
1451       add_symbolic_output_item sob itm adds item itm to buffer sob .
1452
1453
1454       Since 4.06.0
1455
1456
1457
1458       val  formatter_of_symbolic_output_buffer  :  symbolic_output_buffer  ->
1459       formatter
1460
1461
1462       formatter_of_symbolic_output_buffer  sob  returns  a symbolic formatter
1463       that outputs to symbolic_output_buffer sob .
1464
1465
1466       Since 4.06.0
1467
1468
1469
1470
1471   Convenience formatting functions.
1472       val pp_print_list : ?pp_sep:(formatter -> unit -> unit)  ->  (formatter
1473       -> 'a -> unit) -> formatter -> 'a list -> unit
1474
1475
1476       pp_print_list ?pp_sep pp_v ppf l prints items of list l , using pp_v to
1477       print each item, and calling pp_sep between items ( pp_sep defaults  to
1478       Format.pp_print_cut .  Does nothing on empty lists.
1479
1480
1481       Since 4.02.0
1482
1483
1484
1485       val pp_print_text : formatter -> string -> unit
1486
1487
1488       pp_print_text  ppf  s  prints  s  with spaces and newlines respectively
1489       printed using Format.pp_print_space and Format.pp_force_newline .
1490
1491
1492       Since 4.02.0
1493
1494
1495
1496       val pp_print_option : ?none:(formatter -> unit -> unit)  ->  (formatter
1497       -> 'a -> unit) -> formatter -> 'a option -> unit
1498
1499
1500       pp_print_option  ?none  pp_v  ppf  o prints o on ppf using pp_v if o is
1501       Some v and none if it is None .  none prints nothing by default.
1502
1503
1504       Since 4.08
1505
1506
1507
1508       val pp_print_result : ok:(formatter -> 'a -> unit) ->  error:(formatter
1509       -> 'e -> unit) -> formatter -> ('a, 'e) result -> unit
1510
1511
1512       pp_print_result  ~ok ~error ppf r prints r on ppf using ok if r is Ok _
1513       and error if r is Error _ .
1514
1515
1516       Since 4.08
1517
1518
1519
1520
1521   Formatted pretty-printing
1522       Module Format provides a complete set  of  printf  like  functions  for
1523       pretty-printing using format string specifications.
1524
1525       Specific  annotations  may  be  added  in  the  format  strings to give
1526       pretty-printing commands to the pretty-printing engine.
1527
1528       Those annotations are introduced in the  format  strings  using  the  @
1529       character.  For  instance,  @  means  a space break, @, means a cut, @[
1530       opens a new box, and @] closes the last open box.
1531
1532       val fprintf : formatter -> ('a, formatter, unit) format -> 'a
1533
1534
1535
1536
1537
1538       fprintf ff fmt arg1 ... argN formats the arguments arg1 to argN accord‐
1539       ing  to the format string fmt , and outputs the resulting string on the
1540       formatter ff .
1541
1542       The format string fmt is a character string which contains three  types
1543       of objects: plain characters and conversion specifications as specified
1544       in the Printf module, and pretty-printing indications specific  to  the
1545       Format module.
1546
1547       The pretty-printing indication characters are introduced by a @ charac‐
1548       ter, and their meanings are:
1549
1550       - @[ : open a pretty-printing box. The type and offset of the  box  may
1551       be  optionally  specified  with  the following syntax: the < character,
1552       followed by an optional box type indication, then an  optional  integer
1553       offset,  and  the closing > character.  Pretty-printing box type is one
1554       of h , v , hv , b , or  hov  .   '  h  '  stands  for  an  'horizontal'
1555       pretty-printing box, ' v ' stands for a 'vertical' pretty-printing box,
1556       ' hv ' stands for an 'horizontal/vertical' pretty-printing box, '  b  '
1557       stands  for an 'horizontal-or-vertical' pretty-printing box demonstrat‐
1558       ing indentation, '  hov  '  stands  a  simple  'horizontal-or-vertical'
1559       pretty-printing  box.   For  instance,  @[<hov  2>  opens  an 'horizon‐
1560       tal-or-vertical' pretty-printing box with  indentation  2  as  obtained
1561       with open_hovbox 2 .  For more details about pretty-printing boxes, see
1562       the various box opening functions open_*box .
1563
1564       - @] : close the most recently opened pretty-printing box.
1565
1566       - @, : output a 'cut' break hint, as with print_cut () .
1567
1568       - @ : output a 'space' break hint, as with print_space () .
1569
1570       - @; : output a 'full' break hint as with print_break . The nspaces and
1571       offset  parameters  of  the break hint may be optionally specified with
1572       the following syntax: the < character, followed by an  integer  nspaces
1573       value,  then  an  integer  offset  ,  and a closing > character.  If no
1574       parameters are provided, the good break defaults  to  a  'space'  break
1575       hint.
1576
1577       - @.  : flush the pretty-printer and split the line, as with print_new‐
1578       line () .
1579
1580       - @<n> : print the following item as if it were of length n  .   Hence,
1581       printf  @<0>%s  arg prints arg as a zero length string.  If @<n> is not
1582       followed by a conversion specification, then the following character of
1583       the format is printed as if it were of length n .
1584
1585       - @{ : open a semantic tag. The name of the tag may be optionally spec‐
1586       ified with the following  syntax:  the  <  character,  followed  by  an
1587       optional  string specification, and the closing > character. The string
1588       specification is any character string that does not contain the closing
1589       character  '>' . If omitted, the tag name defaults to the empty string.
1590       For  more  details  about  semantic  tags,  see  the   functions   For‐
1591       mat.open_stag and Format.close_stag .
1592
1593       - @} : close the most recently opened semantic tag.
1594
1595       -  @?   :  flush  the  pretty-printer as with print_flush () .  This is
1596       equivalent to the conversion %!  .
1597
1598       - @\n : force a newline, as with force_newline () , not the normal  way
1599       of pretty-printing, you should prefer using break hints inside a verti‐
1600       cal pretty-printing box.
1601
1602       Note: To prevent the interpretation of a @ character as a pretty-print‐
1603       ing indication, escape it with a % character.  Old quotation mode @@ is
1604       deprecated since it is not compatible with formatted input  interpreta‐
1605       tion of character '@' .
1606
1607       Example:  printf  @[%s@  %d@]@.  x  =  1  is equivalent to open_box ();
1608       print_string  x  =  ;  print_space  ();  print_int  1;  close_box   ();
1609       print_newline  () .  It prints x = 1 within a pretty-printing 'horizon‐
1610       tal-or-vertical' box.
1611
1612       val printf : ('a, formatter, unit) format -> 'a
1613
1614       Same as fprintf above, but output on std_formatter .
1615
1616
1617
1618       val eprintf : ('a, formatter, unit) format -> 'a
1619
1620       Same as fprintf above, but output on err_formatter .
1621
1622
1623
1624       val sprintf : ('a, unit, string) format -> 'a
1625
1626       Same as printf above, but instead of printing on a formatter, returns a
1627       string  containing  the  result of formatting the arguments.  Note that
1628       the pretty-printer queue is flushed at the end of each call to  sprintf
1629       .
1630
1631       In  case of multiple and related calls to sprintf to output material on
1632       a single string, you should consider using fprintf with the  predefined
1633       formatter  str_formatter  and  call  flush_str_formatter  () to get the
1634       final result.
1635
1636       Alternatively, you can use Format.fprintf with a formatter writing to a
1637       buffer of your own: flushing the formatter and the buffer at the end of
1638       pretty-printing returns the desired string.
1639
1640
1641
1642       val asprintf : ('a, formatter, unit, string) format4 -> 'a
1643
1644       Same as printf above, but instead of printing on a formatter, returns a
1645       string  containing the result of formatting the arguments.  The type of
1646       asprintf is general enough to interact nicely with %a conversions.
1647
1648
1649       Since 4.01.0
1650
1651
1652
1653       val dprintf : ('a, formatter, unit, formatter -> unit) format4 -> 'a
1654
1655       Same as Format.fprintf , except the formatter  is  the  last  argument.
1656       dprintf  ... a b c is a function of type formatter -> unit which can be
1657       given to a format specifier %t .
1658
1659       This can be used as a replacement for Format.asprintf to delay  format‐
1660       ting  decisions. Using the string returned by Format.asprintf in a for‐
1661       matting context forces formatting decisions to be taken  in  isolation,
1662       and the final string may be created prematurely.  Format.dprintf allows
1663       delay of formatting decisions until the  final  formatting  context  is
1664       known.   For  example:  let  t = Format.dprintf %i@ %i@ %i 1 2 3 in ...
1665       Format.printf @[<v>%t@] t
1666
1667
1668
1669       Since 4.08.0
1670
1671
1672
1673       val ifprintf : formatter -> ('a, formatter, unit) format -> 'a
1674
1675       Same as fprintf above, but does not print anything.  Useful  to  ignore
1676       some material when conditionally printing.
1677
1678
1679       Since 3.10.0
1680
1681
1682
1683
1684       Formatted Pretty-Printing with continuations.
1685
1686       val  kfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit,
1687       'a) format4 -> 'b
1688
1689       Same as fprintf above, but instead of returning immediately, passes the
1690       formatter to its first argument at the end of printing.
1691
1692
1693
1694       val kdprintf : ((formatter -> unit) -> 'a) -> ('b, formatter, unit, 'a)
1695       format4 -> 'b
1696
1697       Same as Format.dprintf above, but  instead  of  returning  immediately,
1698       passes the suspended printer to its first argument at the end of print‐
1699       ing.
1700
1701
1702       Since 4.08.0
1703
1704
1705
1706       val ikfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit,
1707       'a) format4 -> 'b
1708
1709       Same  as kfprintf above, but does not print anything.  Useful to ignore
1710       some material when conditionally printing.
1711
1712
1713       Since 3.12.0
1714
1715
1716
1717       val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b
1718
1719       Same as sprintf above, but instead of returning the string,  passes  it
1720       to the first argument.
1721
1722
1723
1724       val  kasprintf : (string -> 'a) -> ('b, formatter, unit, 'a) format4 ->
1725       'b
1726
1727       Same as asprintf above, but instead of returning the string, passes  it
1728       to the first argument.
1729
1730
1731       Since 4.03
1732
1733
1734
1735
1736   Deprecated
1737       val bprintf : Buffer.t -> ('a, formatter, unit) format -> 'a
1738
1739       Deprecated.   This  function is error prone. Do not use it.  This func‐
1740       tion is neither compositional nor incremental,  since  it  flushes  the
1741       pretty-printer queue at each call.
1742
1743       If you need to print to some buffer b , you must first define a format‐
1744       ter writing to b , using let to_b = formatter_of_buffer b  ;  then  use
1745       regular calls to Format.fprintf with formatter to_b .
1746
1747
1748
1749       val kprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b
1750
1751       Deprecated.  An alias for ksprintf .
1752
1753
1754
1755       val  set_all_formatter_output_functions  : out:(string -> int -> int ->
1756       unit) -> flush:(unit -> unit) -> newline:(unit -> unit) ->  spaces:(int
1757       -> unit) -> unit
1758
1759       Deprecated.  Subsumed by set_formatter_out_functions .
1760
1761
1762
1763       val  get_all_formatter_output_functions : unit -> (string -> int -> int
1764       -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
1765
1766       Deprecated.  Subsumed by get_formatter_out_functions .
1767
1768
1769
1770       val pp_set_all_formatter_output_functions : formatter -> out:(string ->
1771       int  ->  int -> unit) -> flush:(unit -> unit) -> newline:(unit -> unit)
1772       -> spaces:(int -> unit) -> unit
1773
1774       Deprecated.  Subsumed by pp_set_formatter_out_functions .
1775
1776
1777
1778       val  pp_get_all_formatter_output_functions  :  formatter  ->  unit   ->
1779       (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int
1780       -> unit)
1781
1782       Deprecated.  Subsumed by pp_get_formatter_out_functions .
1783
1784
1785
1786
1787   String tags
1788       val pp_open_tag : formatter -> tag -> unit
1789
1790       Deprecated.  Subsumed by Format.pp_open_stag .
1791
1792
1793
1794       val open_tag : tag -> unit
1795
1796       Deprecated.  Subsumed by Format.open_stag .
1797
1798
1799
1800       val pp_close_tag : formatter -> unit -> unit
1801
1802       Deprecated.  Subsumed by Format.pp_close_stag .
1803
1804
1805
1806       val close_tag : unit -> unit
1807
1808       Deprecated.  Subsumed by Format.close_stag .
1809
1810
1811       type formatter_tag_functions = {
1812        mark_open_tag : tag -> string ;
1813        mark_close_tag : tag -> string ;
1814        print_open_tag : tag -> unit ;
1815        print_close_tag : tag -> unit ;
1816        }
1817
1818
1819       Deprecated.  Subsumed by Format.formatter_stag_functions .
1820
1821
1822
1823       val pp_set_formatter_tag_functions : formatter  ->  formatter_tag_func‐
1824       tions -> unit
1825
1826       Deprecated.  Subsumed by Format.pp_set_formatter_stag_functions .
1827
1828
1829       This function will erase non-string tag formatting functions.
1830
1831
1832
1833       val set_formatter_tag_functions : formatter_tag_functions -> unit
1834
1835       Deprecated.  Subsumed by Format.set_formatter_stag_functions .
1836
1837
1838
1839       val  pp_get_formatter_tag_functions  :  formatter  ->  unit  -> format‐
1840       ter_tag_functions
1841
1842       Deprecated.  Subsumed by Format.pp_get_formatter_stag_functions .
1843
1844
1845
1846       val get_formatter_tag_functions : unit -> formatter_tag_functions
1847
1848       Deprecated.  Subsumed by Format.get_formatter_stag_functions .
1849
1850
1851
1852
1853
1854OCamldoc                          2019-07-30                         Format(3)
Impressum