Skip to content

Commit

Permalink
add Pp.verbatimf (#18)
Browse files Browse the repository at this point in the history
* add Pp.verbatimf

Follow the same naming scheme as existing functions textf and
paragraphf.

Signed-off-by: Mathieu Barbin <[email protected]>
  • Loading branch information
mbarbin authored Nov 16, 2023
1 parent faf15db commit 6749c14
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------

- Add `Pp.verbatimf`. (#18, @mbarbin)

- Remove `of_fmt` constructor. (#17, @Alizter)

1.2.0
Expand Down
1 change: 1 addition & 0 deletions src/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ let hbox t = Hbox t
let hvbox ?(indent = 0) t = Hvbox (indent, t)
let hovbox ?(indent = 0) t = Hovbox (indent, t)
let verbatim x = Verbatim x
let verbatimf fmt = Printf.ksprintf verbatim fmt
let char x = Char x
let custom_break ~fits ~breaks = Break (fits, breaks)

Expand Down
3 changes: 3 additions & 0 deletions src/pp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ val concat_mapi : ?sep:'tag t -> 'a list -> f:(int -> 'a -> 'tag t) -> 'tag t
(** An indivisible block of text. *)
val verbatim : string -> 'tag t

(** Same as [verbatim] but take a format string as argument. *)
val verbatimf : ('a, unit, string, 'tag t) format4 -> 'a

(** A single character. *)
val char : char -> 'tag t

Expand Down
4 changes: 4 additions & 0 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Hello x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x
|}]

let%expect_test "verbatimf" =
print (Pp.verbatimf "ident%d" 42);
[%expect {| ident42 |}]

(* Difference between box and hovbox *)
let%expect_test _ =
let pp f = f (xs 50 ++ Pp.break ~nspaces:2 ~shift:(-1) ++ xs 10) in
Expand Down

0 comments on commit 6749c14

Please sign in to comment.