Esc

format_range

procedureextensionsince 0.36.1Source
  • macOS: format_range works on macOS
  • Linux: format_range works on Linux
  • Windows: format_range works on Windows
  • Wasm: format_range works on Wasm

Formats only the top-level statements that the byte range from to to touches, and returns the whole text with everything outside them untouched. The range snaps outward to whole statements (and to the lines they share with their neighbours); an empty range selects the statement it sits in, and a range that touches none, or sits after a // jaifmt: off, changes nothing.

Signature

format_range :: (
    text: string,
    from: s64,
    to: s64,
    config: Format_Config = .{}
) -> (result: string, ok: bool, error: string)
Example↗
text := "a::1;\nb  ::  2;\nc  ::  3;\n";
formatted, ok, error := format_range(text, 8, 8);
assert(ok && formatted == "a::1;\nb :: 2;\nc  ::  3;\n");

See also