caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benoit Vaugon <benoit.vaugon@gmail.com>
To: Matthieu Dubuget <matthieu.dubuget@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] I never succeeded in using Format
Date: Thu, 6 Mar 2014 17:47:12 +0100	[thread overview]
Message-ID: <CACi101zkvYJr3vMzdQ7SC9E_7fPufUQ4beQDQC=yR_1NyDu6tw@mail.gmail.com> (raw)
In-Reply-To: <5318A3A8.8050402@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1916 bytes --]

Hi,

The set_margin function configure the std_formatter, ie the formatter of
the standard output (the one used by printf). To change the margin when
printing in a buffer, you can run something like this :

# open Format;;
# let buf = Buffer.create 16;;
val buf : Buffer.t = <abstr>
# let formatter = formatter_of_buffer buf;;
val formatter : Format.formatter = <abstr>
# pp_set_margin formatter 9;;
- : unit = ()
# fprintf formatter "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
- : unit = ()
# Buffer.contents buf;;
- : string = "111,222,\n333,444,\n555,666\n"

Best regards,
Benoît Vaugon.



2014-03-06 17:34 GMT+01:00 Matthieu Dubuget <matthieu.dubuget@gmail.com>:

> Is the following behaviour expected, or a misunderstanding of mine?
>
> In short, I'd like to use the Format module to prepare an
> output inside a Buffer.t. But a basic <hov> box does not
> break lines as I would expect, while printf does.
>
> OCaml version 4.01.0
>
> # open Format;;
> # printf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
> 111,222,333,444,555,666
> - : unit = ()
> # set_margin 9;;
> - : unit
> = ()
> # printf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
> 111,222,
> 333,444,
> 555,666
> - : unit
> = ()
> # sprintf "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
> - : string
> =
> "111,222,333,444,555,666\n"
>
> Why doesn't sprintf exhibit the same behaviour as printf?
> Trying with fprintf...
>
> # fprintf str_formatter "@[<hov0>111,@,222,@,333,@,444,@,555,@,666@]@.";;
> - : unit
> = ()
> # flush_str_formatter ();;
> - : string
> =
> "111,222,333,444,555,666\n"
>
> --
> Matthieu Dubuget
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 2966 bytes --]

  parent reply	other threads:[~2014-03-06 16:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06 16:34 Matthieu Dubuget
2014-03-06 16:46 ` Jeremy Yallop
2014-03-06 16:47 ` Benoit Vaugon [this message]
2014-03-06 17:02   ` Matthieu Dubuget
2014-03-06 17:06     ` David Sheets
2014-03-06 17:09       ` Matthieu Dubuget
2014-03-06 19:08         ` Martin Jambon
2014-03-07  7:20           ` Raphaël Proust
2014-03-10  0:47             ` oleg
2014-03-10 11:28               ` Bob Atkey
2014-03-11  9:32                 ` oleg
2014-03-14 10:21                   ` Francois Pottier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACi101zkvYJr3vMzdQ7SC9E_7fPufUQ4beQDQC=yR_1NyDu6tw@mail.gmail.com' \
    --to=benoit.vaugon@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=matthieu.dubuget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).