On Fri, Feb 14, 2020 at 5:34 AM Lassi Kortela <xxxxxx@lassi.io> wrote:
 
Scheme (and Lisp generally) are blessed in the coding style department
because people already agree about indenting with 2 spaces, where to put
the parentheses, etc. It would be quite a simple effort to write an
auto-formatter that applies the rules most people are already using anyway.

It would need a few special cases for things like indenting `define`,
`call-with-input-string`, R6RS `library` and R7RS `define-library`, etc.
There are not many of those exceptions and they are quite simple to
handle. For much of the other stuff we could simply copy the current
behavior of Emacs scheme-mode and add some heuristic line breaking to
avoid long lines.

I like the idea of a standard pretty-printer for Scheme code, but there is at least one difficulty specific to Lisps and Schemes: since we can extend the language with macros, we can add new forms to the language for which the indentation isn't automatically clear.  For example,  here's an expression for defining an HTML template in a DSL I wrote:

(define-html-template (write-blog-navigation-links)
    ((about (header-about-link))
     (rss (header-rss-link "/blog/rss")))
  ((div class "about") about)
  rss)

Note subexpression on the second and third lines.  It's a block of let-style bindings.  That block is indented to make it clear that it's different from the HTML expressions that follow.  Under Emacs, I use (put 'define-html-template 'scheme-indent-function 2) to automate that indentation.  A pretty-printer couldn't figure that setting out automatically.