1Format(3)                          OCamldoc                          Format(3)
2
3
4

NAME

6       Format - Pretty printing.
7

Module

9       Module   Format
10

Documentation

12       Module Format
13        : sig end
14
15
16       Pretty printing.
17
18       This  module  implements  a  pretty-printing  facility to format values
19       within 'pretty-printing boxes'.  The  pretty-printer  splits  lines  at
20       specified  break  hints,  and indents lines according to the box struc‐
21       ture.
22
23       For a gentle introduction to the basics of pretty-printing using Format
24       , read http://caml.inria.fr/resources/doc/guides/format.en.html.
25
26       You  may  consider  this module as providing an extension to the printf
27       facility  to  provide  automatic  line  splitting.  The   addition   of
28       pretty-printing  annotations  to  your regular printf formats gives you
29       fancy indentation and line  breaks.   Pretty-printing  annotations  are
30       described below in the documentation of the function Format.fprintf .
31
32       You  may  also  use  the explicit box management and printing functions
33       provided by this module. This style is more basic but more verbose than
34       the fprintf concise formats.
35
36       For  instance,  the sequence open_box 0; print_string x = ; print_space
37       (); print_int 1; close_box (); print_newline  ()  that  prints  x  =  1
38       within a pretty-printing box, can be abbreviated as printf @[%s@ %i@]@.
39       x = 1 , or even shorter printf @[x =@ %i@]@. 1 .
40
41       Rule of thumb for casual users of this library:
42
43       -use simple boxes (as obtained by open_box 0 );
44
45       -use simple break hints (as obtained by print_cut  ()  that  outputs  a
46       simple break hint, or by print_space () that outputs a space indicating
47       a break hint);
48
49       -once a box is opened, display its material with basic  printing  func‐
50       tions (e. g.  print_int and print_string );
51
52       -when  the  material  for  a box has been printed, call close_box () to
53       close the box;
54
55       -at the end of your routine, flush the pretty-printer  to  display  all
56       the remaining material, e.g. evaluate print_newline () .
57
58       The behaviour of pretty-printing commands is unspecified if there is no
59       opened pretty-printing box. Each box opened via one of the open_  func‐
60       tions  below must be closed using close_box for proper formatting. Oth‐
61       erwise, some of the material printed in the boxes may not be output, or
62       may be formatted incorrectly.
63
64       In  case  of  interactive  use,  the system closes all opened boxes and
65       flushes all pending text (as with  the  print_newline  function)  after
66       each  phrase. Each phrase is therefore executed in the initial state of
67       the pretty-printer.
68
69       Warning: the material output by the following functions is  delayed  in
70       the pretty-printer queue in order to compute the proper line splitting.
71       Hence, you should not mix calls to the printing functions of the  basic
72       I/O  system  with  calls  to  the  functions of this module: this could
73       result in some strange output seemingly unrelated with  the  evaluation
74       order of printing commands.
75
76
77
78
79
80
81
82       === Boxes ===
83
84
85       val open_box : int -> unit
86
87
88       open_box d opens a new pretty-printing box with offset d .
89
90       This box prints material as much as possible on every line.
91
92       A  break  hint  splits the line if there is no more room on the line to
93       print the remainder of the box.  A break hint also splits the  line  if
94       the  splitting  ``moves  to  the  left''  (i.e. it gives an indentation
95       smaller than the one of the current line).
96
97       This box is the general purpose pretty-printing box.
98
99       If the pretty-printer splits the line in the box, offset d is added  to
100       the current indentation.
101
102
103
104       val close_box : unit -> unit
105
106       Closes the most recently opened pretty-printing box.
107
108
109
110
111       === Formatting functions ===
112
113
114       val print_string : string -> unit
115
116
117       print_string str prints str in the current box.
118
119
120
121       val print_as : int -> string -> unit
122
123
124       print_as len str prints str in the current box. The pretty-printer for‐
125       mats str as if it were of length len .
126
127
128
129       val print_int : int -> unit
130
131       Prints an integer in the current box.
132
133
134
135       val print_float : float -> unit
136
137       Prints a floating point number in the current box.
138
139
140
141       val print_char : char -> unit
142
143       Prints a character in the current box.
144
145
146
147       val print_bool : bool -> unit
148
149       Prints a boolean in the current box.
150
151
152
153
154       === Break hints ===
155
156
157       === A 'break hint' tells the pretty-printer to  output  some  space  or
158       split  the  line  whichever  way is more appropriate to the current box
159       splitting rules.  Break hints are used to separate printing  items  and
160       are  mandatory  to  let  the  pretty-printer  correctly split lines and
161       indent items.  Simple break hints are: - the 'space': output a space or
162       split the line if appropriate, - the 'cut': split the line if appropri‐
163       ate.  Note: the notions of space and line splitting  are  abstract  for
164       the  pretty-printing  engine,  since  those  notions  can be completely
165       defined by the programmer.  However, in the pretty-printer default set‐
166       ting, ``output a space'' simply means printing a space character (ASCII
167       code 32) and ``split the line'' is printing a newline character  (ASCII
168       code 10). ===
169
170
171       val print_space : unit -> unit
172
173
174       print_space () the 'space' break hint: the pretty-printer may split the
175       line at this point, otherwise it prints one space.  It is equivalent to
176       print_break 1 0 .
177
178
179
180       val print_cut : unit -> unit
181
182
183       print_cut  ()  the  'cut'  break hint: the pretty-printer may split the
184       line at this point, otherwise it prints nothing.  It is  equivalent  to
185       print_break 0 0 .
186
187
188
189       val print_break : int -> int -> unit
190
191
192       print_break  nspaces  offset  the 'full' break hint: the pretty-printer
193       may split the line at this point, otherwise it prints nspaces spaces.
194
195       If the pretty-printer splits the line, offset is added to  the  current
196       indentation.
197
198
199
200       val print_flush : unit -> unit
201
202       Flushes  the pretty printer: all opened boxes are closed, and all pend‐
203       ing text is displayed.
204
205
206
207       val print_newline : unit -> unit
208
209       Equivalent to print_flush followed by a new line.
210
211
212
213       val force_newline : unit -> unit
214
215       Forces a  new  line  in  the  current  box.   Not  the  normal  way  of
216       pretty-printing,  since  the  new  line does not reset the current line
217       count.  You should prefer using break hints within a vertcal box.
218
219
220
221       val print_if_newline : unit -> unit
222
223       Executes the next formatting command if the  preceding  line  has  just
224       been split. Otherwise, ignore the next formatting command.
225
226
227
228
229       === Margin ===
230
231
232       val set_margin : int -> unit
233
234
235       set_margin   d  sets  the  right  margin  to  d  (in  characters):  the
236       pretty-printer splits lines that overflow the right margin according to
237       the  break  hints given.  Nothing happens if d is smaller than 2.  If d
238       is too large, the right margin is set to the maximum  admissible  value
239       (which is greater than 10^9 ).
240
241
242
243       val get_margin : unit -> int
244
245       Returns the position of the right margin.
246
247
248
249
250       === Maximum indentation limit ===
251
252
253       val set_max_indent : int -> unit
254
255
256       set_max_indent  d  sets the maximum indentation limit of lines to d (in
257       characters): once this limit is reached, new boxes are rejected to  the
258       left,  if they do not fit on the current line.  Nothing happens if d is
259       smaller than 2.  If d is too large, the limit is  set  to  the  maximum
260       admissible value (which is greater than 10 ^ 9 ).
261
262
263
264       val get_max_indent : unit -> int
265
266       Return the maximum indentation limit (in characters).
267
268
269
270
271       ===  Formatting  depth: maximum number of boxes allowed before ellipsis
272       ===
273
274
275       val set_max_boxes : int -> unit
276
277
278       set_max_boxes max sets  the  maximum  number  of  boxes  simultaneously
279       opened.   Material inside boxes nested deeper is printed as an ellipsis
280       (more precisely as the text returned by get_ellipsis_text () ).   Noth‐
281       ing happens if max is smaller than 2.
282
283
284
285       val get_max_boxes : unit -> int
286
287       Returns the maximum number of boxes allowed before ellipsis.
288
289
290
291       val over_max_boxes : unit -> bool
292
293       Tests if the maximum number of boxes allowed have already been opened.
294
295
296
297
298       === Advanced formatting ===
299
300
301       val open_hbox : unit -> unit
302
303
304       open_hbox () opens a new 'horizontal' pretty-printing box.
305
306       This box prints material on a single line.
307
308       Break  hints in a horizontal box never split the line.  (Line splitting
309       may still occur inside boxes nested deeper).
310
311
312
313       val open_vbox : int -> unit
314
315
316       open_vbox d opens a new 'vertical' pretty-printing box with offset d .
317
318       This box prints material on as many lines as break hints in the box.
319
320       Every break hint in a vertical box splits the line.
321
322       If the pretty-printer splits the line in the box, d  is  added  to  the
323       current indentation.
324
325
326
327       val open_hvbox : int -> unit
328
329
330       open_hvbox d opens a new 'horizontal-vertical' pretty-printing box with
331       offset d .
332
333       This box behaves as an horizontal box if it fits on a single line, oth‐
334       erwise it behaves as a vertical box.
335
336       If  the  pretty-printer  splits  the line in the box, d is added to the
337       current indentation.
338
339
340
341       val open_hovbox : int -> unit
342
343
344       open_hovbox d opens a new 'horizontal-or-vertical' pretty-printing  box
345       with offset d .
346
347       This box prints material as much as possible on every line.
348
349       A  break  hint  splits the line if there is no more room on the line to
350       print the remainder of the box.
351
352       If the pretty-printer splits the line in the box, d  is  added  to  the
353       current indentation.
354
355
356
357
358       === Ellipsis ===
359
360
361       val set_ellipsis_text : string -> unit
362
363       Set  the text of the ellipsis printed when too many boxes are opened (a
364       single dot, .  , by default).
365
366
367
368       val get_ellipsis_text : unit -> string
369
370       Return the text of the ellipsis.
371
372
373
374
375       === Semantic Tags ===
376
377
378       type tag = string
379
380
381
382
383
384
385       === Semantic tags (or simply tags) are used to decorate  printed  enti‐
386       ties  for  user's  defined  purposes, e.g. setting font and giving size
387       indications for a display device, or marking delimitation  of  semantic
388       entities  (e.g. HTML or TeX elements or terminal escape sequences).  By
389       default, those tags do not influence line  splitting  calculation:  the
390       tag  'markers' are not considered as part of the printing material that
391       drives line splitting (in other words, the length of those  strings  is
392       considered  as zero for line splitting).  Thus, tag handling is in some
393       sense transparent to pretty-printing and does not interfere with  usual
394       indentation.  Hence,  a  single pretty printing routine can output both
395       simple 'verbatim' material or richer decorated output depending on  the
396       treatment of tags. By default, tags are not active, hence the output is
397       not decorated with tag information. Once set_tags is set to  true,  the
398       pretty  printer  engine  honours  tags and decorates the output accord‐
399       ingly.  When a tag has been opened (or closed), it is both and  succes‐
400       sively 'printed' and 'marked'. Printing a tag means calling a formatter
401       specific function with the name of  the  tag  as  argument:  that  'tag
402       printing' function can then print any regular material to the formatter
403       (so that this material is enqueued as usual in the formatter queue  for
404       further  line  splitting computation). Marking a tag means to output an
405       arbitrary string (the 'tag marker'), directly into the output device of
406       the  formatter.  Hence,  the  formatter specific 'tag marking' function
407       must return the tag marker string associated to its tag argument. Being
408       flushed  directly  into  the output device of the formatter, tag marker
409       strings are not considered as part of the printing material that drives
410       line splitting (in other words, the length of the strings corresponding
411       to tag markers is considered as zero for line splitting). In  addition,
412       advanced  users may take advantage of the specificity of tag markers to
413       be precisely output when the pretty printer has already  decided  where
414       to  split  the  lines, and precisely when the queue is flushed into the
415       output device.  In the spirit of HTML tags,  the  default  tag  marking
416       functions  output  tags enclosed in < and > : hence, the opening marker
417       of tag t is <t> and the closing marker </t>  .   Default  tag  printing
418       functions  just do nothing.  Tag marking and tag printing functions are
419       user definable and can be set by  calling  set_formatter_tag_functions.
420       ===
421
422
423       val open_tag : tag -> unit
424
425
426       open_tag  t  opens the tag named t ; the print_open_tag function of the
427       formatter is called with t as argument; the tag marker mark_open_tag  t
428       will be flushed into the output device of the formatter.
429
430
431
432       val close_tag : unit -> unit
433
434
435       close_tag  () closes the most recently opened tag t .  In addition, the
436       print_close_tag function of the formatter is called with t as argument.
437       The  marker  mark_close_tag t will be flushed into the output device of
438       the formatter.
439
440
441
442       val set_tags : bool -> unit
443
444
445       set_tags b turns on or off the treatment of tags (default is off).
446
447
448
449       val set_print_tags : bool -> unit
450
451
452       set_print_tags b turns on or off the printing of tags.
453
454
455
456       val set_mark_tags : bool -> unit
457
458
459       set_mark_tags b turns on or off the output of tag markers.
460
461
462
463       val get_print_tags : unit -> bool
464
465       Return the current status of tags printing.
466
467
468
469       val get_mark_tags : unit -> bool
470
471       Return the current status of tags marking.
472
473
474
475
476       === Redirecting the standard formatter output ===
477
478
479       val set_formatter_out_channel : Pervasives.out_channel -> unit
480
481       Redirect the pretty-printer output to the given channel.  (All the out‐
482       put  functions  of the standard formatter are set to the default output
483       functions printing to the given channel.)
484
485
486
487       val set_formatter_output_functions : (string -> int -> int -> unit)  ->
488       (unit -> unit) -> unit
489
490
491       set_formatter_output_functions  out  flush redirects the pretty-printer
492       output functions to the functions out and flush .
493
494       The out function performs all the pretty-printer string output.  It  is
495       called  with  a string s , a start position p , and a number of charac‐
496       ters n ; it is supposed to output characters p to p + n - 1 of s .
497
498       The flush function is called whenever  the  pretty-printer  is  flushed
499       (via  conversion  %!   , or pretty-printing indications @?  or @.  , or
500       using low level functions print_flush or print_newline ).
501
502
503
504       val get_formatter_output_functions : unit -> (string -> int ->  int  ->
505       unit) * (unit -> unit)
506
507       Return the current output functions of the pretty-printer.
508
509
510
511
512       === Changing the meaning of standard formatter pretty printing ===
513
514
515       ===  The  Format module is versatile enough to let you completely rede‐
516       fine the meaning of pretty printing: you may provide your own functions
517       to  define how to handle indentation, line splitting, and even printing
518       of all the characters that have to be printed! ===
519
520
521       type formatter_out_functions = {
522        out_string : string -> int -> int -> unit ;
523        out_flush : unit -> unit ;
524        out_newline : unit -> unit ;
525        out_spaces : int -> unit ;
526        }
527
528
529       Since 4.01.0
530
531
532
533       val set_formatter_out_functions : formatter_out_functions -> unit
534
535
536       set_formatter_out_functions f Redirect the pretty-printer output to the
537       functions  f.out_string  and  f.out_flush  as  described in set_format‐
538       ter_output_functions . In addition, the  pretty-printer  function  that
539       outputs a newline is set to the function f.out_newline and the function
540       that outputs indentation spaces is set to the function f.out_spaces .
541
542       This way, you can change the meaning of indentation (which can be some‐
543       thing  else than just printing space characters) and the meaning of new
544       lines opening (which can be connected to any other action needed by the
545       application  at hand). The two functions f.out_spaces and f.out_newline
546       are normally connected to f.out_string  and  f.out_flush  :  respective
547       default  values  for  f.out_space  and  f.out_newline  are f.out_string
548       (String.make n ' ') 0 n and f.out_string \n 0 1 .
549
550
551       Since 4.01.0
552
553
554
555       val get_formatter_out_functions : unit -> formatter_out_functions
556
557       Return the current output functions of  the  pretty-printer,  including
558       line  splitting and indentation functions. Useful to record the current
559       setting and restore it afterwards.
560
561
562       Since 4.01.0
563
564
565
566
567       === Changing the meaning of printing semantic tags ===
568
569
570       type formatter_tag_functions = {
571        mark_open_tag : tag -> string ;
572        mark_close_tag : tag -> string ;
573        print_open_tag : tag -> unit ;
574        print_close_tag : tag -> unit ;
575        }
576
577
578       The tag handling functions specific to a formatter: mark  versions  are
579       the  'tag marking' functions that associate a string marker to a tag in
580       order for the pretty-printing engine to flush those markers as 0 length
581       tokens  in  the output device of the formatter.  print versions are the
582       'tag printing' functions that can perform regular printing when  a  tag
583       is closed or opened.
584
585
586
587       val set_formatter_tag_functions : formatter_tag_functions -> unit
588
589
590       set_formatter_tag_functions tag_funs changes the meaning of opening and
591       closing tags to use the functions in tag_funs .
592
593       When opening a tag name t , the string t is passed to the  opening  tag
594       marking  function  (the  mark_open_tag  field of the record tag_funs ),
595       that must return the opening tag marker for that name.  When  the  next
596       call  to close_tag () happens, the tag name t is sent back to the clos‐
597       ing tag marking function (the mark_close_tag field of  record  tag_funs
598       ), that must return a closing tag marker for that name.
599
600       The  print_  field of the record contains the functions that are called
601       at tag opening and tag closing time, to output regular material in  the
602       pretty-printer queue.
603
604
605
606       val get_formatter_tag_functions : unit -> formatter_tag_functions
607
608       Return the current tag functions of the pretty-printer.
609
610
611
612
613       === Multiple formatted output ===
614
615
616       type formatter
617
618
619       Abstract  data corresponding to a pretty-printer (also called a format‐
620       ter) and all its machinery.
621
622       Defining new pretty-printers permits unrelated output  of  material  in
623       parallel   on  several  output  channels.   All  the  parameters  of  a
624       pretty-printer are local to a formatter:  margin,  maximum  indentation
625       limit,  maximum number of boxes simultaneously opened, ellipsis, and so
626       on, are specific to each pretty-printer and may be fixed independently.
627       Given  a  Pervasives.out_channel  output  channel  oc , a new formatter
628       writing  to  that  channel  is  simply  obtained  by  calling   format‐
629       ter_of_out_channel  oc  .   Alternatively,  the make_formatter function
630       allocates a new formatter with explicit output and  flushing  functions
631       (convenient to output material to strings for instance).
632
633
634
635       val formatter_of_out_channel : Pervasives.out_channel -> formatter
636
637
638       formatter_of_out_channel  oc returns a new formatter that writes to the
639       corresponding channel oc .
640
641
642
643       val std_formatter : formatter
644
645       The standard formatter used by the formatting functions  above.  It  is
646       defined as formatter_of_out_channel stdout .
647
648
649
650       val err_formatter : formatter
651
652       A  formatter to use with formatting functions below for output to stan‐
653       dard error. It is defined as formatter_of_out_channel stderr .
654
655
656
657       val formatter_of_buffer : Buffer.t -> formatter
658
659
660       formatter_of_buffer b returns a new formatter writing to buffer b .  As
661       usual,  the  formatter has to be flushed at the end of pretty printing,
662       using pp_print_flush or pp_print_newline , to display all  the  pending
663       material.
664
665
666
667       val stdbuf : Buffer.t
668
669       The string buffer in which str_formatter writes.
670
671
672
673       val str_formatter : formatter
674
675       A  formatter  to  use with formatting functions below for output to the
676       stdbuf string buffer.  str_formatter is defined as  formatter_of_buffer
677       stdbuf .
678
679
680
681       val flush_str_formatter : unit -> string
682
683       Returns the material printed with str_formatter , flushes the formatter
684       and resets the corresponding buffer.
685
686
687
688       val make_formatter : (string -> int -> int -> unit) -> (unit  ->  unit)
689       -> formatter
690
691
692       make_formatter  out flush returns a new formatter that writes according
693       to the output function out , and the  flushing  function  flush  .  For
694       instance,  a  formatter to the Pervasives.out_channel oc is returned by
695       make_formatter (Pervasives.output oc) (fun () -> Pervasives.flush oc) .
696
697
698
699
700       === Basic functions to use with formatters ===
701
702
703       val pp_open_hbox : formatter -> unit -> unit
704
705
706
707
708       val pp_open_vbox : formatter -> int -> unit
709
710
711
712
713       val pp_open_hvbox : formatter -> int -> unit
714
715
716
717
718       val pp_open_hovbox : formatter -> int -> unit
719
720
721
722
723       val pp_open_box : formatter -> int -> unit
724
725
726
727
728       val pp_close_box : formatter -> unit -> unit
729
730
731
732
733       val pp_open_tag : formatter -> string -> unit
734
735
736
737
738       val pp_close_tag : formatter -> unit -> unit
739
740
741
742
743       val pp_print_string : formatter -> string -> unit
744
745
746
747
748       val pp_print_as : formatter -> int -> string -> unit
749
750
751
752
753       val pp_print_int : formatter -> int -> unit
754
755
756
757
758       val pp_print_float : formatter -> float -> unit
759
760
761
762
763       val pp_print_char : formatter -> char -> unit
764
765
766
767
768       val pp_print_bool : formatter -> bool -> unit
769
770
771
772
773       val pp_print_break : formatter -> int -> int -> unit
774
775
776
777
778       val pp_print_cut : formatter -> unit -> unit
779
780
781
782
783       val pp_print_space : formatter -> unit -> unit
784
785
786
787
788       val pp_force_newline : formatter -> unit -> unit
789
790
791
792
793       val pp_print_flush : formatter -> unit -> unit
794
795
796
797
798       val pp_print_newline : formatter -> unit -> unit
799
800
801
802
803       val pp_print_if_newline : formatter -> unit -> unit
804
805
806
807
808       val pp_set_tags : formatter -> bool -> unit
809
810
811
812
813       val pp_set_print_tags : formatter -> bool -> unit
814
815
816
817
818       val pp_set_mark_tags : formatter -> bool -> unit
819
820
821
822
823       val pp_get_print_tags : formatter -> unit -> bool
824
825
826
827
828       val pp_get_mark_tags : formatter -> unit -> bool
829
830
831
832
833       val pp_set_margin : formatter -> int -> unit
834
835
836
837
838       val pp_get_margin : formatter -> unit -> int
839
840
841
842
843       val pp_set_max_indent : formatter -> int -> unit
844
845
846
847
848       val pp_get_max_indent : formatter -> unit -> int
849
850
851
852
853       val pp_set_max_boxes : formatter -> int -> unit
854
855
856
857
858       val pp_get_max_boxes : formatter -> unit -> int
859
860
861
862
863       val pp_over_max_boxes : formatter -> unit -> bool
864
865
866
867
868       val pp_set_ellipsis_text : formatter -> string -> unit
869
870
871
872
873       val pp_get_ellipsis_text : formatter -> unit -> string
874
875
876
877
878       val pp_set_formatter_out_channel : formatter ->  Pervasives.out_channel
879       -> unit
880
881
882
883
884       val  pp_set_formatter_output_functions : formatter -> (string -> int ->
885       int -> unit) -> (unit -> unit) -> unit
886
887
888
889
890       val pp_get_formatter_output_functions : formatter -> unit -> (string ->
891       int -> int -> unit) * (unit -> unit)
892
893
894
895
896       val  pp_set_formatter_tag_functions  : formatter -> formatter_tag_func‐
897       tions -> unit
898
899
900
901
902       val pp_get_formatter_tag_functions  :  formatter  ->  unit  ->  format‐
903       ter_tag_functions
904
905
906
907
908       val  pp_set_formatter_out_functions  : formatter -> formatter_out_func‐
909       tions -> unit
910
911       Since 4.01.0
912
913
914
915       val pp_get_formatter_out_functions  :  formatter  ->  unit  ->  format‐
916       ter_out_functions
917
918       These  functions  are  the basic ones: usual functions operating on the
919       standard formatter are defined via partial evaluation of  these  primi‐
920       tives.  For instance, print_string is equal to pp_print_string std_for‐
921       matter .
922
923
924       Since 4.01.0
925
926
927
928       val pp_flush_formatter : formatter -> unit
929
930
931       pp_flush_formatter fmt flushes fmt 's internal queue, ensuring that all
932       the  printing  and  flushing  actions have been performed. In addition,
933       this operation will close all boxes and reset the state of the  format‐
934       ter.
935
936       This  will not flush fmt 's output. In most cases, the user may want to
937       use Format.pp_print_flush instead.
938
939
940       Since 4.04.0
941
942
943
944
945       === Convenience formatting functions.  ===
946
947
948       val pp_print_list : ?pp_sep:(formatter -> unit -> unit)  ->  (formatter
949       -> 'a -> unit) -> formatter -> 'a list -> unit
950
951
952       pp_print_list ?pp_sep pp_v ppf l prints items of list l , using pp_v to
953       print each item, and calling pp_sep between items ( pp_sep defaults  to
954       Format.pp_print_cut ).  Does nothing on empty lists.
955
956
957       Since 4.02.0
958
959
960
961       val pp_print_text : formatter -> string -> unit
962
963
964       pp_print_text  ppf  s  prints  s  with spaces and newlines respectively
965       printed with Format.pp_print_space and Format.pp_force_newline .
966
967
968       Since 4.02.0
969
970
971
972
973       === printf like functions for pretty-printing.  ===
974
975
976       val fprintf : formatter -> ('a, formatter, unit)  Pervasives.format  ->
977       'a
978
979
980
981
982
983       ===  fprintf  ff  fmt  arg1 ... argN formats the arguments arg1 to argN
984       according to the format string fmt, and outputs the resulting string on
985       the  formatter ff.  The format fmt is a character string which contains
986       three types of objects: plain characters and conversion  specifications
987       as specified in the Printf module, and pretty-printing indications spe‐
988       cific to the Format module.  The pretty-printing indication  characters
989       are  introduced  by a @ character, and their meanings are: - @[: open a
990       pretty-printing box. The type and offset of the box may  be  optionally
991       specified  with  the  following syntax: the < character, followed by an
992       optional box type indication, then an optional integer offset, and  the
993       closing  >  character.   Box  type  is one of h, v, hv, b, or hov.  'h'
994       stands for an 'horizontal' box, 'v' stands for a 'vertical'  box,  'hv'
995       stands  for  an  'horizontal-vertical' box, 'b' stands for an 'horizon‐
996       tal-or-vertical' box demonstrating indentation, 'hov' stands  a  simple
997       'horizontal-or-vertical'  box.  For instance, @[<hov 2> opens an 'hori‐
998       zontal-or-vertical' box with indentation 2 as obtained with open_hovbox
999       2.  For more details about boxes, see the various box opening functions
1000       open_*box.  - @]: close the most recently opened  pretty-printing  box.
1001       -  @,: output a 'cut' break hint, as with print_cut ().  - @ : output a
1002       'space' break hint, as with print_space ().   -  @;:  output  a  'full'
1003       break  hint  as  with print_break. The nspaces and offset parameters of
1004       the break hint may be optionally specified with the  following  syntax:
1005       the  < character, followed by an integer nspaces value, then an integer
1006       offset, and a closing > character.  If no parameters are provided,  the
1007       good  break  defaults  to a 'space' break hint.  - @.: flush the pretty
1008       printer and split the line, as with print_newline ().   -  @<n>:  print
1009       the following item as if it were of length n.  Hence, printf @<0>%s arg
1010       prints arg as a zero length string.  If @<n> is not followed by a  con‐
1011       version  specification,  then  the following character of the format is
1012       printed as if it were of length n.  - @{: open a tag. The name  of  the
1013       tag  may be optionally specified with the following syntax: the < char‐
1014       acter, followed by an optional string specification, and the closing  >
1015       character.  The  string specification is any character string that does
1016       not contain the  closing  character  '>'.  If  omitted,  the  tag  name
1017       defaults  to  the  empty  string.  For more details about tags, see the
1018       functions open_tag and close_tag.  - @}: close the most recently opened
1019       tag.   -  @?: flush the pretty printer as with print_flush ().  This is
1020       equivalent to the conversion %!.  -  @\n:  force  a  newline,  as  with
1021       force_newline  (),  not  the  normal way of pretty-printing, you should
1022       prefer using break hints inside a vertical box.  Note: If you  need  to
1023       prevent  the interpretation of a @ character as a pretty-printing indi‐
1024       cation, you must escape it with a % character.  Old quotation  mode  @@
1025       is deprecated since it is not compatible with formatted input interpre‐
1026       tation of character '@'.  Example: printf @[%s@ %d@]@. x = 1 is equiva‐
1027       lent  to  open_box  (); print_string x = ; print_space (); print_int 1;
1028       close_box (); print_newline ().  It prints x = 1 within a pretty-print‐
1029       ing 'horizontal-or-vertical' box. ===
1030
1031
1032       val printf : ('a, formatter, unit) Pervasives.format -> 'a
1033
1034       Same as fprintf above, but output on std_formatter .
1035
1036
1037
1038       val eprintf : ('a, formatter, unit) Pervasives.format -> 'a
1039
1040       Same as fprintf above, but output on err_formatter .
1041
1042
1043
1044       val sprintf : ('a, unit, string) Pervasives.format -> 'a
1045
1046       Same as printf above, but instead of printing on a formatter, returns a
1047       string containing the result of formatting the  arguments.   Note  that
1048       the  pretty-printer queue is flushed at the end of each call to sprintf
1049       .
1050
1051       In case of multiple and related calls to sprintf to output material  on
1052       a  single string, you should consider using fprintf with the predefined
1053       formatter str_formatter and call  flush_str_formatter  ()  to  get  the
1054       final result.
1055
1056       Alternatively, you can use Format.fprintf with a formatter writing to a
1057       buffer of your own: flushing the formatter and the buffer at the end of
1058       pretty-printing returns the desired string.
1059
1060
1061
1062       val asprintf : ('a, formatter, unit, string) Pervasives.format4 -> 'a
1063
1064       Same as printf above, but instead of printing on a formatter, returns a
1065       string containing the result of formatting the arguments.  The type  of
1066       asprintf is general enough to interact nicely with %a conversions.
1067
1068
1069       Since 4.01.0
1070
1071
1072
1073       val  ifprintf : formatter -> ('a, formatter, unit) Pervasives.format ->
1074       'a
1075
1076       Same as fprintf above, but does not print anything.  Useful  to  ignore
1077       some material when conditionally printing.
1078
1079
1080       Since 3.10.0
1081
1082
1083
1084
1085       === Formatted output functions with continuations. ===
1086
1087
1088       val  kfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit,
1089       'a) Pervasives.format4 -> 'b
1090
1091       Same as fprintf above, but instead of returning immediately, passes the
1092       formatter to its first argument at the end of printing.
1093
1094
1095
1096       val ikfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit,
1097       'a) Pervasives.format4 -> 'b
1098
1099       Same as kfprintf above, but does not print anything.  Useful to  ignore
1100       some material when conditionally printing.
1101
1102
1103       Since 3.12.0
1104
1105
1106
1107       val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) Pervasives.for‐
1108       mat4 -> 'b
1109
1110       Same as sprintf above, but instead of returning the string,  passes  it
1111       to the first argument.
1112
1113
1114
1115       val  kasprintf  :  (string  ->  'a) -> ('b, formatter, unit, 'a) Perva‐
1116       sives.format4 -> 'b
1117
1118       Same as asprintf above, but instead of returning the string, passes  it
1119       to the first argument.
1120
1121
1122       Since 4.03
1123
1124
1125
1126
1127       === Deprecated ===
1128
1129
1130       val bprintf : Buffer.t -> ('a, formatter, unit) Pervasives.format -> 'a
1131
1132       Deprecated.  This function is error prone. Do not use it.
1133
1134       If you need to print to some buffer b , you must first define a format‐
1135       ter writing to b , using let to_b = formatter_of_buffer b  ;  then  use
1136       regular calls to Format.fprintf on formatter to_b .
1137
1138
1139
1140       val  kprintf : (string -> 'a) -> ('b, unit, string, 'a) Pervasives.for‐
1141       mat4 -> 'b
1142
1143       Deprecated.  An alias for ksprintf .
1144
1145
1146
1147       val set_all_formatter_output_functions : out:(string -> int ->  int  ->
1148       unit)  -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int
1149       -> unit) -> unit
1150
1151       Deprecated.  Subsumed by set_formatter_out_functions .
1152
1153
1154
1155       val get_all_formatter_output_functions : unit -> (string -> int ->  int
1156       -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
1157
1158       Deprecated.  Subsumed by get_formatter_out_functions .
1159
1160
1161
1162       val pp_set_all_formatter_output_functions : formatter -> out:(string ->
1163       int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit  ->  unit)
1164       -> spaces:(int -> unit) -> unit
1165
1166       Deprecated.  Subsumed by pp_set_formatter_out_functions .
1167
1168
1169
1170       val   pp_get_all_formatter_output_functions  :  formatter  ->  unit  ->
1171       (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int
1172       -> unit)
1173
1174       Deprecated.  Subsumed by pp_get_formatter_out_functions .
1175
1176
1177
1178
1179       === Tabulation boxes are deprecated. ===
1180
1181
1182       val pp_open_tbox : formatter -> unit -> unit
1183
1184       Deprecated.  since 4.03.0
1185
1186
1187
1188       val pp_close_tbox : formatter -> unit -> unit
1189
1190       Deprecated.  since 4.03.0
1191
1192
1193
1194       val pp_print_tbreak : formatter -> int -> int -> unit
1195
1196       Deprecated.  since 4.03.0
1197
1198
1199
1200       val pp_set_tab : formatter -> unit -> unit
1201
1202       Deprecated.  since 4.03.0
1203
1204
1205
1206       val pp_print_tab : formatter -> unit -> unit
1207
1208       Deprecated.  since 4.03.0
1209
1210
1211
1212       val open_tbox : unit -> unit
1213
1214       Deprecated.  since 4.03.0
1215
1216
1217
1218       val close_tbox : unit -> unit
1219
1220       Deprecated.  since 4.03.0
1221
1222
1223
1224       val print_tbreak : int -> int -> unit
1225
1226       Deprecated.  since 4.03.0
1227
1228
1229
1230       val set_tab : unit -> unit
1231
1232       Deprecated.  since 4.03.0
1233
1234
1235
1236       val print_tab : unit -> unit
1237
1238       Deprecated.  since 4.03.0
1239
1240
1241
1242
1243
12442018-04-14                          source:                          Format(3)
Impressum