- Listlike expressions (e.g. tuples, calls, paren-blocks, vectors) that
span multiple lines now always require a leading and a trailing
newline (and thus a trailing comma from previous listlike spacing
code). For example
```diff
-f(a,
- b)
+f(
+ a,
+ b,
+)
```
- Listlike expressions are now hard indents instead of the
soft/continuation style from before. This looks better.
- Vectors (K"vect" and K"ref") are now spaced like lists.
- Fix some bugs in spaces-around-operators when there where hidden
newlines at the beginning of the call chain.
Closes#9.
This is a huge patch and adds formatting of indentation. It is slightly
difficult to come up with a good set of rules but I think what is here
is pretty nice. There are two types of indentation: block/hard
indentation and continuation/soft indentation.
Block indentation are context independent and are thus "hard" or
required in the sense that they always happen. Block indentation are
enabled for all `x - end` blocks where `x` is one of `begin`, `do`,
`for`, `function`, `if`, `let`, `quote`, `struct`, `try`, `while`. A
notable exception is `module`, but one idea is to indent nested modules
(in the same file).
Continuation or soft indents are context dependent in the sense that if
nested within another soft indent they extra indents are skipped. Soft
indentation applies to all expressions spanning multiple lines.
For example, newlines in operator chains:
```julia
a + b * c +
d # soft indent
```
function calls
```julia
foo(
a, b c, d # soft indent
)
```
etc.
This patch changes the code quite a bit:
- Use an IOBuffer for the source text instead of a string. This make it
simpler to use byte index instead of string index.
- Utilize the seekability of the output IOBuffer to backtrack changes
when child nodes want to format something.
- Build an formatted tree as we go: unchanged nodes alias the source
tree and we build new nodes when things change.