@@ -262,7 +262,15 @@ let fmt_constant c ?epi {pconst_desc; pconst_loc= loc} =
262
262
| Pconst_char (_ , s ) -> wrap " '" " '" @@ str s
263
263
| Pconst_string (s , loc' , Some delim ) ->
264
264
Cmts. fmt c loc'
265
- @@ wrap_k (str (" {" ^ delim ^ " |" )) (str (" |" ^ delim ^ " }" )) (str s)
265
+ @@ (* If a multiline string has newlines in it, the configuration might
266
+ specify it should get treated as a "long" box element. To do so,
267
+ we pretend it is 1000 characters long. *)
268
+ ( if
269
+ c.conf.fmt_opts.break_around_multiline_strings.v
270
+ && String. mem s '\n'
271
+ then str_as 1000
272
+ else str )
273
+ (Format_. sprintf " {%s|%s|%s}" delim s delim)
266
274
| Pconst_string (_ , loc' , None) -> (
267
275
let delim = [" @," ; " @;" ] in
268
276
let contains_pp_commands s =
@@ -513,18 +521,19 @@ let sequence_blank_line c (l1 : Location.t) (l2 : Location.t) =
513
521
loop l1.loc_end (Cmts. remaining_before c.cmts l2)
514
522
| `Compact -> false
515
523
516
- let fmt_quoted_string key ext s = function
517
- | None ->
518
- wrap_k (str (Format_. sprintf " {%s%s|" key ext)) (str " |}" ) (str s)
524
+ let fmt_quoted_string c key ext s maybe_delim =
525
+ ( if c.conf.fmt_opts.break_around_multiline_strings.v && String. mem s '\n'
526
+ then str_as 1000
527
+ else str )
528
+ @@
529
+ match maybe_delim with
530
+ | None -> Format_. sprintf " {%s%s|%s|}" key ext s
519
531
| Some delim ->
520
532
let ext_and_delim =
521
533
if String. is_empty delim then ext
522
534
else Format_. sprintf " %s %s" ext delim
523
535
in
524
- wrap_k
525
- (str (Format_. sprintf " {%s%s|" key ext_and_delim))
526
- (str (Format_. sprintf " |%s}" delim))
527
- (str s)
536
+ Format_. sprintf " {%s%s|%s|%s}" key ext_and_delim s delim
528
537
529
538
let fmt_type_var s =
530
539
str " '"
@@ -557,7 +566,7 @@ let rec fmt_extension_aux c ctx ~key (ext, pld) =
557
566
assert (not (Cmts. has_after c.cmts pexp_loc)) ;
558
567
assert (not (Cmts. has_before c.cmts pstr_loc)) ;
559
568
assert (not (Cmts. has_after c.cmts pstr_loc)) ;
560
- hvbox 0 (fmt_quoted_string (Ext.Key. to_string key) ext str delim)
569
+ hvbox 0 (fmt_quoted_string c (Ext.Key. to_string key) ext str delim)
561
570
| _, PStr [({pstr_loc; _} as si)], (Pld _ | Str _ | Top )
562
571
when Source. extension_using_sugar ~name: ext ~payload: pstr_loc ->
563
572
fmt_structure_item c ~last: true ~ext ~semisemi: false (sub_str ~ctx si)
0 commit comments