Leaving part of a file alone
Comments switch the formatter off for part of a file:
<kscript>
<!-- kscript-fmt: off -->
<let name="grid" value="[
[1, 0, 0],
[0, 1, 0],
[0, 0, 1] ]" />
<!-- kscript-fmt: on -->
<!-- kscript-fmt-ignore: kept on one line on purpose -->
<for each="i" in="1..3"><echo>$i</echo></for>
</kscript>// kscript-fmt: off
$grid = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1] ]
// kscript-fmt: on
// kscript-fmt-ignore: kept on one line on purpose
for i in 1..3 {
echo $i
}- Everything from
<!-- kscript-fmt: off -->to<!-- kscript-fmt: on -->is kept exactly. Without anon, it runs to the end of the element the comment is in (or the end of the file). <!-- kscript-fmt-ignore -->keeps the element (or comment) right after it exactly. Anything afterkscript-fmt-ignorein the comment is yours, for saying why.- Only the comment's own line is re-indented, so the region moves with the code around it.
In .kscript files the same comments are written with //. // kscript-fmt: off runs to // kscript-fmt: on or the end of the block it is in, and // kscript-fmt-ignore keeps the next statement, with any block it opens:
<!-- kscript-fmt-ignore: a grid reads better this way -->
<let name="grid">[1, 0, 0,
0, 1, 0,
0, 0, 1]</let>// kscript-fmt-ignore: a grid reads better this way
$grid = [1, 0, 0,
0, 1, 0,
0, 0, 1]