diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8a3da..1ce956b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Include the variable name in the open-log line (just as function name for functions). - Output the description of a for loop body as `` rather than just `[identifier]`. - `Debug_runtime` functions now take an `~entry_id` parameter, set to a per-entry ID generated by `get_entry_id`. +- Small non-atomic sexp values can now be printed inline with the variable name (like sexp atoms) rather than spread out as trees. ## [0.8.0] -- 2024-01-16 diff --git a/minidebug_runtime.ml b/minidebug_runtime.ml index 687fe7c..78f30fd 100644 --- a/minidebug_runtime.ml +++ b/minidebug_runtime.ml @@ -222,6 +222,8 @@ module PrintBox (Log_to : Debug_ch) = struct let highlighted_roots = ref false let exclude_on_path = ref None let values_first_mode = ref false + let max_inline_sexp_size = ref 20 + let max_inline_sexp_length = ref 50 module B = PrintBox @@ -429,11 +431,19 @@ module PrintBox (Log_to : Debug_ch) = struct let hls, bs = List.split @@ List.map loop l in (List.exists (fun x -> x) hls, B.vlist bs) in - match sexp with - | Atom s | List [ Atom s ] -> - highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ s) - | List [] -> highlight_box @@ B.line descr - | List l -> loop ~as_tree:true @@ List (Atom (descr ^ " =") :: l) + let str = + if sexp_size sexp < min !boxify_sexp_from_size !max_inline_sexp_size then + Sexplib0.Sexp.to_string_hum sexp + else "" + in + if String.length str > 0 && String.length str < !max_inline_sexp_length then + highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ str) + else + match sexp with + | Atom s | List [ Atom s ] -> + highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ s) + | List [] -> highlight_box @@ B.line descr + | List l -> loop ~as_tree:true @@ List (Atom (descr ^ " =") :: l) let num_children () = match !stack with [] -> 0 | { body; _ } :: _ -> List.length body diff --git a/minidebug_runtime.mli b/minidebug_runtime.mli index ca5c270..67474f6 100644 --- a/minidebug_runtime.mli +++ b/minidebug_runtime.mli @@ -106,6 +106,12 @@ module PrintBox : functor (_ : Debug_ch) -> sig val values_first_mode : bool ref (** *) + + val max_inline_sexp_size : int ref + (** *) + + val max_inline_sexp_length : int ref + (** *) end val debug_html :