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