[plt-scheme] Odd Auto-indenting
Eli Barzilay writes:
> On Jun 14, Chris Warrington wrote:
> > What's up with weird auto-formatting in this snippet of code:
> > (call-with-output-file
> > argument
> > (lambda (port) (dump-database (call-with-input-file
> > DATABASE
> > read-cookie-objects)
> > FORMAT
> > LINE_LENGTH
> > port))
> > 'text
> > 'truncate/replace)
> >
> > Notice especially the (call-with-input-file DATABASE read-cookie-objects)
> > sexp. Now that's just weird.
>
> This is a very common indentation pattern -- call-with-input/output-file
> have a "special" first argument, and then a body-like thunk. Emacs
> does the same too (and probably what inspired the indentation code in
> DrScheme).
In particular, the "special" argument usually appears on the same line
as the procedure, but this indentation pattern will always indent the
non-"special" arguments with two spaces rather than lining them up
with the first argument (like a normal procedure). You can change
this in DrScheme's indentation preferences dialog by moving
call-with-values to a different category (or removing it altogether):
"Lambda-like Keywords":
(call-with-input-file
argument
(lambda (port) ...))
(call-with-input-file argument
(lambda (port) ...))
"Begin-like Keywords":
(call-with-input-file
argument
(lambda (port) ...))
(call-with-input-file argument
(lambda (port) ...))
Neither:
(call-with-input-file
argument
(lambda (port) ...))
(call-with-input-file argument
(lambda (port) ...))
I don't know what the difference is between "Begin-like Keywords" and
"Define-like keywords". In Emacs you can specify any number of
"special" arguments:
(put 'module 'scheme-indent-function 2)
(put 'syntax-case 'scheme-indent-function 2)
(put 'syntax-case* 'scheme-indent-function 3)
--dougorleans at gmail.com