ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Feature request: compact lists for really short values

Open MisterDA opened this issue 3 years ago • 1 comments

Hi all, I have this function to format timestamps to dates that got ocamlformat'ed. To me, it seems a bit silly that the months lists gets "expanded" whilst the days list is on a single line. Maybe the heuristic that splits the list on multiple lines could be amended if the values are like, really short in textual representation? I know that's adding more corner-cases, but it could make sense.

let output_generated_by oc binary =
  let t = now () in
  let months =
    [|
      "Jan";
      "Feb";
      "Mar";
      "Apr";
      "May";
      "Jun";
      "Jul";
      "Aug";
      "Sep";
      "Oct";
      "Nov";
      "Dec";
    |]
  in
  let days = [| "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat" |] in
  let time = Unix.gmtime t in
  let date =
    Printf.sprintf "%s, %d %s %d %02d:%02d:%02d GMT" days.(time.Unix.tm_wday)
      time.Unix.tm_mday months.(time.Unix.tm_mon) (time.Unix.tm_year + 1900)
      time.Unix.tm_hour time.Unix.tm_min time.Unix.tm_sec
  in

MisterDA avatar Jul 13 '22 13:07 MisterDA

I think something like #1916 would fit

gpetiot avatar Jul 13 '22 16:07 gpetiot