@@ -262,7 +262,15 @@ let fmt_constant c ?epi {pconst_desc; pconst_loc= loc} =
262262 | Pconst_char (_ , s ) -> wrap " '" " '" @@ str s
263263 | Pconst_string (s , loc' , Some delim ) ->
264264 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)
266274 | Pconst_string (_ , loc' , None) -> (
267275 let delim = [" @," ; " @;" ] in
268276 let contains_pp_commands s =
@@ -513,18 +521,19 @@ let sequence_blank_line c (l1 : Location.t) (l2 : Location.t) =
513521 loop l1.loc_end (Cmts. remaining_before c.cmts l2)
514522 | `Compact -> false
515523
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
519531 | Some delim ->
520532 let ext_and_delim =
521533 if String. is_empty delim then ext
522534 else Format_. sprintf " %s %s" ext delim
523535 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
528537
529538let fmt_type_var s =
530539 str " '"
@@ -557,7 +566,7 @@ let rec fmt_extension_aux c ctx ~key (ext, pld) =
557566 assert (not (Cmts. has_after c.cmts pexp_loc)) ;
558567 assert (not (Cmts. has_before c.cmts pstr_loc)) ;
559568 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)
561570 | _, PStr [({pstr_loc; _} as si)], (Pld _ | Str _ | Top )
562571 when Source. extension_using_sugar ~name: ext ~payload: pstr_loc ->
563572 fmt_structure_item c ~last: true ~ext ~semisemi: false (sub_str ~ctx si)
0 commit comments