By default, scheme mode in Emacs formats code using one space indentation:
(string-append
"foo "
"bar "
"baz")
I want it to be at least two spaces, i.e.:
(string-append
"foo "
"bar "
"baz")
For most modes in Emacs this is pretty easy to change, but I haven't figured out how to do it for scheme. I've looked at the source code for scheme.el as well, and while there is logic in there for doing all kinds of fancy alignments I haven't found a simple way of customizing the "standard indent".
You can set lisp-indent-offset
to 2, but you almost certainly don't want to do this, unless you really know what you're doing.
Lisp-style languages adhere to a slightly different indentation philosophy than other languages. When the first element of an S-expression is alone after the open parenthesis, the convention is to line up the remaining elements to start in the same column:
(first-item
second-item
third-item fourth-item fifth-item
sixth-item)
When the second element is on the same line with the first one, the convention is to align the following elements the second one:
(first-item second-item
third-item fourth-item fifth-item
sixth-item)
This convention applies to sexps that are not special forms, including function calls such as the call to string-append
. Special forms, sexps that are specially interpreted by the evaluator and the compiler, follow slightly different indentation. A form that provides expressions to evaluate will be indented with two spaces:
(lambda (value)
(display value)
(send-eof))
To an experienced Lisper, two spaces subtly denote that the expression is a special form whose two-space-indented subforms will be evaluated in sequence. When you create your own special forms using define-syntax
or defmacro
, you can tell Emacs to indent their subforms the same way:
;; define a CL-style `unless` macro...
(defmacro unless (test &rest forms)
`(or ,test (progn ,@forms)))
;; ...and tell emacs to indent its body forms with two spaces
;; (unless (= value 0)
;; (display value)
;; (send-eof))
(put 'unless 'lisp-indent-function 2)
Changing the indentation level would send the wrong signal to the reader about what is going on, detracting from your code. If you don't like how Emacs indents your call to string-append
, I suggest to switch to the second form, which will automatically indent the strings further to the right:
(string-append "foo "
"bar "
"baz")