Re: dynamic pretty-printing
Sergei Egorov 22 Sep 2026 04:42 UTC
What a wonderful idea, html-style dynamic reflowing of S-expressions with
information provided by the printer, but not rendered directly, so the
terminal itself can finish the job!
> It would be nice if SRFI-272 could make use of these facilities.
Strictly speaking, nothing in SRFI-272 needs to be changed for that:
it does not specify where line breaks should happen, and it has all
the parameters needed to collect and pass information to the port
doing the rendering. A Kawa implementation can check if the output port
is connected to DomTerm, and the width parameter is set to, say, 'dynamic,
it could send the escapes through the pp-tint handler via (kawa pprint)'s
pprint-start-logical-block and friends while normal output goes through
the pp-emit handler as write-like single-line output. I believe it is
possible to tailor the 'advanced' printer to do all these things.
On Monday, September 21, 2026 5:26:16 PM (-04:00), Per Bothner wrote:
> Kawa has an unique (?) feature in that it can defer line-breaking and
> indentation to a suitable terminal (specifically DomTerm). If the
> terminal changes line width, the output is re-formatted - even for
output
> from previous commands - even if the kawa command has finished running.
>
> You can see it in action here:
https://domterm.org/saved/dt-prettynested.html
> Try changing the window width. You can also click triangles to show/hide
sections.
> This is a transcript of a terminal session, but with embedded control
> sequences to mark blocks, soft line-breaks (multiple kinds, as in Common
Lisp),
> and indentation. Some Javascript code does the actual line-breaking.
> This line-breaking is normally in the context of an actual "live"
terminal session,
> but can also be done (as in the demo) in a "saved" session
("transcript").
>
> Here is an old blog article:
https://per.bothner.com/blog/2017/dynamic-prettyprinting/
>
> It would be nice if SRFI-272 could make use of these facilities.