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