You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/indentation.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,13 +161,37 @@ Indentation prefixes can consist of spaces and/or tabs. Indentation widths are t
161
161
162
162
###Indentation and Braces
163
163
164
-
Indentation can be mixed freely with braces. For interpreting indentation inside braces, the following rules apply.
164
+
Indentation can be mixed freely with braces `{...}`, aswellasbrackets `[...]` and parentheses `(...)`. For interpreting indentation inside such regions, the following rules apply.
165
165
166
166
1. The assumed indentation width of a multiline region enclosed in braces is the
167
167
indentation width of the first token that starts a new line after the opening brace.
168
168
169
-
2. On encountering a closing brace `}`, asmany `<outdent>` tokens asnecessary are
170
-
inserted to close all open indentation regions inside the pair of braces.
169
+
2. The assumed indentation width of a multiline region inside brackets or parentheses is:
170
+
171
+
-if the opening bracket or parenthesis is at the end of a line, the indentation width of token following it,
172
+
- otherwise, the indentation width of the enclosing region.
173
+
174
+
3. On encountering a closing brace `}`, bracket `]` or parenthesis `)`, asmany `<outdent>` tokens asnecessary are inserted to close all open nested indentation regions.
175
+
176
+
For instance, consider:
177
+
```scala
178
+
{
179
+
valx= f(x: Int, y =>
180
+
x * (
181
+
y +1
182
+
) +
183
+
(x +
184
+
x)
185
+
)
186
+
}
187
+
```
188
+
-Here, the indentation width of the region enclosed by the braces is 3 (i.e. the indentation width of the
189
+
statement starting with`val`).
190
+
-The indentation width of the region in parentheses that follows `f` is also 3, since the opening
191
+
parenthesis is not at the end of a line.
192
+
-The indentation width of the region in parentheses around `y + 1` is 9
193
+
(i.e. the indentation width of `y + 1`).
194
+
-Finally, the indentation width of the last region in parentheses starting with`(x` is 6 (i.e. the indentation width of the indented region following the `=>`.
0 commit comments