Has anyone worked on pretty printers / formatters ...
# linking-together
f
Has anyone worked on pretty printers / formatters for (textual) source code already? I'm currently looking through different papers and implementations and I still don't really know the limitations of different approaches. Also, do you use such tools and what are your experiences with them? Where don't they work as expected?
y
Perhaps in a different form than what you mean, but all projectional editors pretty-print the AST to present it to the user.
f
I think that's very similar to traditional pretty printing, isn't it? How do you render code in lamdu? I'm especially interested in the layout algorithm ("where to put line breaks depending on available window width")
y
An important consideration to note is that you don’t want things to move too much as you edit, so we wanted something fairly “stable”:
Oh and another implicit consideration of course is that we want to lay out things given a certain width. Horizontal scroll is bad but vertical scroll is fine. So:
Nodes have a horizontal/wide layout option and a vertical option. If everything fits horizontally then it is laid out horizontally, otherwise the top level node is laid out vertically, with the same process applied to its children.
f
I've tried this (switching nodes to vertical layout top-down) before but found that more complex programs and nested / chained function calls look weird unfortunately. What's your experience in lamdu regarding this?
d
Would it make sense to provide reasonable defaults (even if not perfect), but then also allow it to be manually toggled?
y
@Felix Kohlgrüber I’m pretty satisfied with how it turns out. @Dan Cook adding these choices would mean you won’t have responsive design. I.e the code won’t look ideal when you read it from your phone because you laid it out for your pc etc
👍 1
✔️ 1