<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>book/src/guides/indent.md - fork/helix @ 25.07</title>
<meta name="description" content="book/src/guides/indent.md in fork/helix at 25.07.">
<meta property="og:title" content="book/src/guides/indent.md - fork/helix @ 25.07">
<meta property="og:description" content="book/src/guides/indent.md in fork/helix at 25.07.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="25.07" data-tip="5cda70e86637c376bdfaaf3383872e44d7622ff8">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/helix</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/helix</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Adam Perkowski</span><span class="commit-message" data-commit="850c9f691e771bf8a4a5c1307d23788db7097f7f">Fixed headings (# / ##) to match other docs (#11192)</span><span class="snapshot-sha sha" data-commit="850c9f691e771bf8a4a5c1307d23788db7097f7f">850c9f69</span><time datetime="2024-07-16T05:29:00+02:00" title="2024-07-16 05:29:00 +0200">2024-07-16</time></p>
<header class="topbar"><details class="switcher"><summary>25.07</summary><div class="menu"><strong>branches</strong><a href="/fork/helix/ref/master/">master</a><strong>tags</strong><a href="/fork/helix/ref/23.05/">23.05</a><a href="/fork/helix/ref/23.10/">23.10</a><a href="/fork/helix/ref/24.03/">24.03</a><a href="/fork/helix/ref/24.07/">24.07</a><a href="/fork/helix/ref/25.01/">25.01</a><a href="/fork/helix/ref/25.01.1/">25.01.1</a><a class="current" href="/fork/helix/ref/25.07/">25.07</a><a href="/fork/helix/ref/25.07.1/">25.07.1</a><a class="all" href="/fork/helix/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/helix/">helix</a> / <a href="/fork/helix/ref/25.07/tree/book/">book</a> / <a href="/fork/helix/ref/25.07/tree/book/src/">src</a> / <a href="/fork/helix/ref/25.07/tree/book/src/guides/">guides</a> / <span class="cur">indent.md</span></nav>
<span class="view-stats"><span>15.2 KiB</span><span>373 lines</span></span><span class="actions"><a class="raw" href="/fork/helix/raw/1e520731af01b2004213c71322817fcfa844e6e4/book/src/guides/indent.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h2>Adding indent queries</h2>
<p>Helix uses tree-sitter to correctly indent new lines. This requires a tree-
sitter grammar and an <code>indent.scm</code> query file placed in <code>runtime/queries/ {language}/indents.scm</code>. The indentation for a line is calculated by traversing
the syntax tree from the lowest node at the beginning of the new line (see
<a href="#indent-queries">Indent queries</a>). Each of these nodes contributes to the total
indent when it is captured by the query (in what way depends on the name of
the capture.</p>
<p>Note that it matters where these added indents begin. For example,
multiple indent level increases that start on the same line only increase
the total indent level by 1. See <a href="#capture-types">Capture types</a>.</p>
<p>By default, Helix uses the <code>hybrid</code> indentation heuristic. This means that
indent queries are not used to compute the expected absolute indentation of a
line but rather the expected difference in indentation between the new and an
already existing line. This difference is then added to the actual indentation
of the already existing line. Since this makes errors in the indent queries
harder to find, it is recommended to disable it when testing via
<code>:set indent-heuristic tree-sitter</code>. The rest of this guide assumes that
the <code>tree-sitter</code> heuristic is used.</p>
<h2>Indent queries</h2>
<p>When Helix is inserting a new line through <code>o</code>, <code>O</code>, or <code>&lt;ret&gt;</code>, to determine
the indent level for the new line, the query in <code>indents.scm</code> is run on the
document. The starting position of the query is the end of the line above where
a new line will be inserted.</p>
<p>For <code>o</code>, the inserted line is the line below the cursor, so that starting
position of the query is the end of the current line.</p>
<pre class="language-rust"><a-k>fn</a-k> <a-f>need_hero</a-f><a-p>(</a-p><a-v>some_hero</a-v><a-p>:</a-p> <a-t>Hero</a-t><a-p>,</a-p> <a-v>life</a-v><a-p>:</a-p> <a-t>Life</a-t><a-p>)</a-p> -&gt; <a-p>{</a-p>
    <a-m>matches!</a-m><a-p>(</a-p>some_hero<a-p>,</a-p> <a-cr>Hero</a-cr> <a-p>{</a-p> <a-c>// ←─────────────────╮</a-c>
        <a-pr>strong</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p><a-c>//←╮  ↑  ↑                     │</a-c>
        <a-pr>fast</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>// │  │  ╰── query start       │</a-c>
        <a-pr>sure</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>// │  ╰───── cursor            ├─ traversal </a-c>
        <a-pr>soon</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>// ╰──────── new line inserted │  start node</a-c>
    <a-p>})</a-p> &amp;&amp;            <a-c>//                             │</a-c>
<a-c>//  ↑                                               │</a-c>
<a-c>//  ╰───────────────────────────────────────────────╯</a-c>
    some_hero &gt; life
<a-p>}</a-p></pre>
<p>For <code>O</code>, the newly inserted line is the <em>current</em> line, so the starting position
of the query is the end of the line above the cursor.</p>
<pre class="language-rust"><a-k>fn</a-k> <a-f>need_hero</a-f><a-p>(</a-p><a-v>some_hero</a-v><a-p>:</a-p> <a-t>Hero</a-t><a-p>,</a-p> <a-v>life</a-v><a-p>:</a-p> <a-t>Life</a-t><a-p>)</a-p> -&gt; <a-p>{</a-p> <a-c>// ←─╮</a-c>
    <a-m>matches!</a-m><a-p>(</a-p>some_hero<a-p>,</a-p> <a-cr>Hero</a-cr> <a-p>{</a-p> <a-c>// ←╮          ↑     │</a-c>
        <a-pr>strong</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p><a-c>//    ↑   ╭───╯          │     │</a-c>
        <a-pr>fast</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>//    │   │ query start ─╯     │</a-c>
        <a-pr>sure</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>//    ╰───┼ cursor             ├─ traversal</a-c>
        <a-pr>soon</a-pr><a-p>:</a-p> <a-co>true</a-co><a-p>,</a-p>  <a-c>//        ╰ new line inserted  │  start node</a-c>
    <a-p>})</a-p> &amp;&amp;            <a-c>//                             │</a-c>
    some_hero &gt; life <a-c>//                             │</a-c>
<a-p>}</a-p> <a-c>// ←──────────────────────────────────────────────╯</a-c></pre>
<p>From this starting node, the syntax tree is traversed up until the root node.
Each indent capture is collected along the way, and then combined according to
their <a href="#capture-types">capture types</a> and <a href="#scopes">scopes</a> to a final indent
level for the line.</p>
<h3>Capture types</h3>
<ul>
<li><code>@indent</code> (default scope <code>tail</code>):
Increase the indent level by 1. Multiple occurrences in the same line <em>do not</em>
stack. If there is at least one <code>@indent</code> and one <code>@outdent</code> capture on the
same line, the indent level isn't changed at all.</li>
<li><code>@outdent</code> (default scope <code>all</code>):
Decrease the indent level by 1. The same rules as for <code>@indent</code> apply.</li>
<li><code>@indent.always</code> (default scope <code>tail</code>):
Increase the indent level by 1. Multiple occurrences on the same line <em>do</em>
stack. The final indent level is <code>@indent.always</code> – <code>@outdent.always</code>. If
an <code>@indent</code> and an <code>@indent.always</code> are on the same line, the <code>@indent</code> is
ignored.</li>
<li><code>@outdent.always</code> (default scope <code>all</code>):
Decrease the indent level by 1. The same rules as for <code>@indent.always</code> apply.</li>
<li><code>@align</code> (default scope <code>all</code>):
Align everything inside this node to some anchor. The anchor is given
by the start of the node captured by <code>@anchor</code> in the same pattern.
Every pattern with an <code>@align</code> should contain exactly one <code>@anchor</code>.
Indent (and outdent) for nodes below (in terms of their starting line)
the <code>@align</code> node is added to the indentation required for alignment.</li>
<li><code>@extend</code>:
Extend the range of this node to the end of the line and to lines that are
indented more than the line that this node starts on. This is useful for
languages like Python, where for the purpose of indentation some nodes (like
functions or classes) should also contain indented lines that follow them.</li>
<li><code>@extend.prevent-once</code>:
Prevents the first extension of an ancestor of this node. For example, in Python
a return expression always ends the block that it is in. Note that this only
stops the extension of the next <code>@extend</code> capture. If multiple ancestors are
captured, only the extension of the innermost one is prevented. All other
ancestors are unaffected (regardless of whether the innermost ancestor would
actually have been extended).</li>
</ul>
<h4><code>@indent</code> / <code>@outdent</code></h4>
<p>Consider this example:</p>
<pre class="language-rust"><a-k>fn</a-k> <a-f>shout</a-f><a-p>(</a-p><a-v>things</a-v><a-p>:</a-p> <a-t>Vec</a-t><a-p>&lt;</a-p><a-t>Thing</a-t><a-p>&gt;)</a-p> <a-p>{</a-p>
    <a-c>//                       ↑</a-c>
    <a-c>//                       ├───────────────────────╮ indent level</a-c>
    <a-c>//                    @indent                    ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c>
    <a-c>//                                               │</a-c>
    <a-k>let</a-k> it_all = |out| <a-p>{</a-p> things<a-p>.</a-p><a-f>filter</a-f><a-p>(</a-p>|thing| <a-p>{</a-p> <a-c>//  │      1</a-c>
    <a-c>//                 ↑                       ↑     │</a-c>
    <a-c>//                 ├───────────────────────┼─────┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c>
    <a-c>//              @indent                 @indent  │</a-c>
    <a-c>//                                               │      2</a-c>
        thing<a-p>.</a-p><a-f>can_do_with</a-f><a-p>(</a-p>out<a-p>)</a-p> <a-c>//                    │</a-c>
    <a-p>})};</a-p> <a-c>//                                          ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c>
  <a-c>//↑↑↑                                              │      1</a-c>
<a-p>}</a-p> <a-c>//╰┼┴──────────────────────────────────────────────┴┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c>
<a-c>// 3x @outdent</a-c></pre>
<pre class="language-query"><a-p>((</a-p><a-v>block</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>indent</a-t><a-p>)</a-p>
<a-p>[</a-p><a-s>&quot;}&quot;</a-s> <a-s>&quot;)&quot;</a-s><a-p>]</a-p> <a-p>@</a-p><a-t>outdent</a-t></pre>
<p>Note how on the second line, we have two blocks begin on the same line. In this
case, since both captures occur on the same line, they are combined and only
result in a net increase of 1. Also note that the closing <code>}</code>s are part of the
<code>@indent</code> captures, but the 3 <code>@outdent</code>s also combine into 1 and result in that
line losing one indent level.</p>
<h4><code>@extend</code> / <code>@extend.prevent-once</code></h4>
<p>For an example of where <code>@extend</code> can be useful, consider Python, which is
whitespace-sensitive.</p>
<pre class="language-query"><a-p>]</a-p>
  <a-p>(</a-p><a-v>parenthesized_expression</a-v><a-p>)</a-p>
  <a-p>(</a-p><a-v>function_definition</a-v><a-p>)</a-p>
  <a-p>(</a-p><a-v>class_definition</a-v><a-p>)</a-p>
<a-p>]</a-p> <a-p>@</a-p>indent</pre>
<pre class="language-python"><a-k>class</a-k> <a-cr>Hero</a-cr>:
    <a-k>def</a-k> <a-f>__init__</a-f>(<a-v>self</a-v>, <a-v>strong</a-v>, <a-v>fast</a-v>, <a-v>sure</a-v>, <a-v>soon</a-v>):<a-c>#  ←─╮</a-c>
        <a-v>self</a-v>.<a-pr>is_strong</a-pr> <a-o>=</a-o> <a-v>strong</a-v> <a-c>#                     │</a-c>
        <a-v>self</a-v>.<a-pr>is_fast</a-pr> <a-o>=</a-o> <a-v>fast</a-v>     <a-c># ╭─── query start    │</a-c>
        <a-v>self</a-v>.<a-pr>is_sure</a-pr> <a-o>=</a-o> <a-v>sure</a-v>     <a-c># │ ╭─ cursor         │</a-c>
        <a-v>self</a-v>.<a-pr>is_soon</a-pr> <a-o>=</a-o> <a-v>soon</a-v>     <a-c># │ │                 │</a-c>
        <a-c>#     ↑            ↑      │ │                 │</a-c>
        <a-c>#     │            ╰──────╯ │                 │</a-c>
        <a-c>#     ╰─────────────────────╯                 │</a-c>
        <a-c>#                                             ├─ traversal</a-c>
    <a-k>def</a-k> <a-f>need_hero</a-f>(<a-v>self</a-v>, <a-v>life</a-v>):         <a-c>#              │  start node</a-c>
        <a-k>return</a-k> (                       <a-c>#              │</a-c>
            <a-v>self</a-v>.<a-pr>is_strong</a-pr>             <a-c>#              │</a-c>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_fast</a-pr>           <a-c>#              │</a-c>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_sure</a-pr>           <a-c>#              │</a-c>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_soon</a-pr>           <a-c>#              │</a-c>
            <a-o>and</a-o> <a-v>self</a-v> <a-o>&gt;</a-o> <a-v>life</a-v>            <a-c>#              │</a-c>
        ) <a-c># ←─────────────────────────────────────────╯</a-c></pre>
<p>Without braces to catch the scope of the function, the smallest descendant of
the cursor on a line feed ends up being the entire inside of the class. Because
of this, it will miss the entire function node and its indent capture, leading
to an indent level one too small.</p>
<p>To address this case, <code>@extend</code> tells helix to "extend" the captured node's span
to the line feed and every consecutive line that has a greater indent level than
the line of the node.</p>
<pre class="language-query"><a-p>(</a-p><a-v>parenthesized_expression</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>indent</a-t>

<a-p>]</a-p>
  <a-p>(</a-p><a-v>function_definition</a-v><a-p>)</a-p>
  <a-p>(</a-p><a-v>class_definition</a-v><a-p>)</a-p>
<a-p>]</a-p> <a-p>@</a-p>indent <a-p>@</a-p>extend</pre>
<pre class="language-python"><a-k>class</a-k> <a-cr>Hero</a-cr>:
    <a-k>def</a-k> <a-f>__init__</a-f>(<a-v>self</a-v>, <a-v>strong</a-v>, <a-v>fast</a-v>, <a-v>sure</a-v>, <a-v>soon</a-v>):<a-c>#  ←─╮</a-c>
        <a-v>self</a-v>.<a-pr>is_strong</a-pr> <a-o>=</a-o> <a-v>strong</a-v> <a-c>#                     │</a-c>
        <a-v>self</a-v>.<a-pr>is_fast</a-pr> <a-o>=</a-o> <a-v>fast</a-v>     <a-c># ╭─── query start    ├─ traversal</a-c>
        <a-v>self</a-v>.<a-pr>is_sure</a-pr> <a-o>=</a-o> <a-v>sure</a-v>     <a-c># │ ╭─ cursor         │  start node</a-c>
        <a-v>self</a-v>.<a-pr>is_soon</a-pr> <a-o>=</a-o> <a-v>soon</a-v>     <a-c># │ │ ←───────────────╯</a-c>
        <a-c>#     ↑            ↑      │ │                 </a-c>
        <a-c>#     │            ╰──────╯ │</a-c>
        <a-c>#     ╰─────────────────────╯</a-c>
    <a-k>def</a-k> <a-f>need_hero</a-f>(<a-v>self</a-v>, <a-v>life</a-v>):
        <a-k>return</a-k> (
            <a-v>self</a-v>.<a-pr>is_strong</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_fast</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_sure</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_soon</a-pr>
            <a-o>and</a-o> <a-v>self</a-v> <a-o>&gt;</a-o> <a-v>life</a-v>
        )</pre>
<p>Furthermore, there are some cases where extending to everything with a greater
indent level may not be desirable. Consider the <code>need_hero</code> function above. If
our cursor is on the last line of the returned expression.</p>
<pre class="language-python"><a-k>class</a-k> <a-cr>Hero</a-cr>:
    <a-k>def</a-k> <a-f>__init__</a-f>(<a-v>self</a-v>, <a-v>strong</a-v>, <a-v>fast</a-v>, <a-v>sure</a-v>, <a-v>soon</a-v>):
        <a-v>self</a-v>.<a-pr>is_strong</a-pr> <a-o>=</a-o> <a-v>strong</a-v>
        <a-v>self</a-v>.<a-pr>is_fast</a-pr> <a-o>=</a-o> <a-v>fast</a-v>
        <a-v>self</a-v>.<a-pr>is_sure</a-pr> <a-o>=</a-o> <a-v>sure</a-v>
        <a-v>self</a-v>.<a-pr>is_soon</a-pr> <a-o>=</a-o> <a-v>soon</a-v>

    <a-k>def</a-k> <a-f>need_hero</a-f>(<a-v>self</a-v>, <a-v>life</a-v>):
        <a-k>return</a-k> (
            <a-v>self</a-v>.<a-pr>is_strong</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_fast</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_sure</a-pr>
            <a-o>and</a-o> <a-v>self</a-v>.<a-pr>is_soon</a-pr>
            <a-o>and</a-o> <a-v>self</a-v> <a-o>&gt;</a-o> <a-v>life</a-v>
        ) <a-c># ←─── cursor</a-c>
    <a-c>#←────────── where cursor should go on new line</a-c></pre>
<p>In Python, the are a few tokens that will always end a scope, such as a return
statement. Since the scope ends, so should the indent level. But because the
function span is extended to every line with a greater indent level, a new line
would just continue on the same level. And an <code>@outdent</code> would not help us here
either, since it would cause everything in the parentheses to become outdented
as well.</p>
<p>To help, we need to signal an end to the extension. We can do this with
<code>@extend.prevent-once</code>.</p>
<pre class="language-query"><a-p>(</a-p><a-v>parenthesized_expression</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>indent</a-t>

<a-p>]</a-p>
  <a-p>(</a-p><a-v>function_definition</a-v><a-p>)</a-p>
  <a-p>(</a-p><a-v>class_definition</a-v><a-p>)</a-p>
<a-p>]</a-p> <a-p>@</a-p>indent <a-p>@</a-p>extend

<a-p>(</a-p><a-v>return_statement</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>extend.prevent-once</a-t></pre>
<h4><code>@indent.always</code> / <code>@outdent.always</code></h4>
<p>As mentioned before, normally if there is more than one <code>@indent</code> or <code>@outdent</code>
capture on the same line, they are combined.</p>
<p>Sometimes, there are cases when you may want to ensure that every indent capture
is additive, regardless of how many occur on the same line. Consider this
example in YAML.</p>
<pre class="language-yaml">  <a-p>-</a-p> <a-pr>foo</a-pr><a-p>:</a-p> <a-s>bar</a-s>
<a-c># ↑ ↑</a-c>
<a-c># │ ╰─────────────── start of map</a-c>
<a-c># ╰───────────────── start of list element</a-c>
    <a-pr>baz</a-pr><a-p>:</a-p> <a-s>quux</a-s> <a-c># ←─── cursor</a-c>
    <a-c># ←───────────── where the cursor should go on a new line</a-c>
    <a-pr>garply</a-pr><a-p>:</a-p> <a-s>waldo</a-s>
  <a-p>-</a-p> <a-pr>quux</a-pr><a-p>:</a-p>
      <a-pr>bar</a-pr><a-p>:</a-p> <a-s>baz</a-s>
    <a-pr>xyzzy</a-pr><a-p>:</a-p> <a-s>thud</a-s>
    <a-pr>fred</a-pr><a-p>:</a-p> <a-s>plugh</a-s></pre>
<p>In YAML, you often have lists of maps. In these cases, the syntax is such that
the list element and the map both start on the same line. But we really do want
to start an indentation for each of these so that subsequent keys in the map
hang over the list and align properly. This is where <code>@indent.always</code> helps.</p>
<pre class="language-query"><a-p>((</a-p><a-v>block_sequence_item</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>item</a-t> <a-p>@</a-p><a-t>indent.always</a-t> <a-p>@</a-p><a-t>extend</a-t>
  <a-p>(#</a-p><a-f>not-one-line</a-f><a-p>?</a-p> <a-p>@</a-p><a-t>item</a-t><a-p>))</a-p>

<a-p>((</a-p><a-v>block_mapping_pair</a-v>
    <a-v>key</a-v><a-p>:</a-p> <a-p>(</a-p><a-s>_</a-s><a-p>)</a-p> <a-p>@</a-p><a-t>key</a-t>
    <a-v>value</a-v><a-p>:</a-p> <a-p>(</a-p><a-s>_</a-s><a-p>)</a-p> <a-p>@</a-p><a-t>val</a-t>
    <a-p>(#</a-p><a-f>not-same-line</a-f><a-p>?</a-p> <a-p>@</a-p><a-t>key</a-t> <a-p>@</a-p><a-t>val</a-t><a-p>)</a-p>
  <a-p>)</a-p> <a-p>@</a-p><a-t>indent.always</a-t> <a-p>@</a-p><a-t>extend</a-t>
<a-p>)</a-p></pre>
<h2>Predicates</h2>
<p>In some cases, an S-expression cannot express exactly what pattern should be matched.
For that, tree-sitter allows for predicates to appear anywhere within a pattern,
similar to how <code>#set!</code> declarations work:</p>
<pre class="language-query"><a-p>(</a-p><a-v>some_kind</a-v>
  <a-p>(</a-p><a-v>child_kind</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>indent</a-t>
  <a-p>(#</a-p><a-f>predicate</a-f><a-p>?</a-p> arg1 arg2 <a-o>...</a-o><a-p>)</a-p>
<a-p>)</a-p></pre>
<p>The number of arguments depends on the predicate that's used.
Each argument is either a capture (<code>@name</code>) or a string (<code>"some string"</code>).
The following predicates are supported by tree-sitter:</p>
<ul>
<li>
<p><code>#eq?</code>/<code>#not-eq?</code>:
The first argument (a capture) must/must not be equal to the second argument
(a capture or a string).</p>
</li>
<li>
<p><code>#match?</code>/<code>#not-match?</code>:
The first argument (a capture) must/must not match the regex given in the
second argument (a string).</p>
</li>
<li>
<p><code>#any-of?</code>/<code>#not-any-of?</code>:
The first argument (a capture) must/must not be one of the other arguments
(strings).</p>
</li>
</ul>
<p>Additionally, we support some custom predicates for indent queries:</p>
<ul>
<li>
<p><code>#not-kind-eq?</code>:
The kind of the first argument (a capture) must not be equal to the second
argument (a string).</p>
</li>
<li>
<p><code>#same-line?</code>/<code>#not-same-line?</code>:
The captures given by the 2 arguments must/must not start on the same line.</p>
</li>
<li>
<p><code>#one-line?</code>/<code>#not-one-line?</code>:
The captures given by the fist argument must/must span a total of one line.</p>
</li>
</ul>
<h3>Scopes</h3>
<p>Added indents don't always apply to the whole node. For example, in most
cases when a node should be indented, we actually only want everything
except for its first line to be indented. For this, there are several
scopes (more scopes may be added in the future if required):</p>
<ul>
<li><code>tail</code>:
This scope applies to everything except for the first line of the
captured node.</li>
<li><code>all</code>:
This scope applies to the whole captured node. This is only different from
<code>tail</code> when the captured node is the first node on its line.</li>
</ul>
<p>For example, imagine we have the following function</p>
<pre class="language-rust"><a-k>fn</a-k> <a-f>aha</a-f><a-p>()</a-p> <a-p>{</a-p> <a-c>// ←─────────────────────────────────────╮</a-c>
  <a-k>let</a-k> take = <a-s>&quot;on me&quot;</a-s><a-p>;</a-p>  <a-c>// ←──────────────╮  scope:  │</a-c>
  <a-k>let</a-k> take = <a-s>&quot;me on&quot;</a-s><a-p>;</a-p>             <a-c>//     ├─ &quot;tail&quot;  ├─ (block) @indent</a-c>
  <a-k>let</a-k> ill = <a-f>be_gone_days</a-f><a-p>(</a-p><a-co>1</a-co> || <a-co>2</a-co><a-p>);</a-p> <a-c>//     │          │</a-c>
<a-p>}</a-p> <a-c>// ←───────────────────────────────────┴──────────┴─ &quot;}&quot; @outdent</a-c>
                                         <a-c>//                scope: &quot;all&quot;</a-c></pre>
<p>We can write the following query with the <code>#set!</code> declaration:</p>
<pre class="language-query"><a-p>((</a-p><a-v>block</a-v><a-p>)</a-p> <a-p>@</a-p><a-t>indent</a-t>
 <a-p>(#</a-p><a-f>set</a-f><a-p>!</a-p> <a-s>&quot;scope&quot;</a-s> <a-s>&quot;tail&quot;</a-s><a-p>))</a-p>
<a-p>(</a-p><a-s>&quot;}&quot;</a-s> <a-p>@</a-p><a-t>outdent</a-t>
 <a-p>(#</a-p><a-f>set</a-f><a-p>!</a-p> <a-s>&quot;scope&quot;</a-s> <a-s>&quot;all&quot;</a-s><a-p>))</a-p></pre>
<p>As we can see, the "tail" scope covers the node, except for the first line.
Everything up to and including the closing brace gets an indent level of 1.
Then, on the closing brace, we encounter an outdent with a scope of "all", which
means the first line is included, and the indent level is cancelled out on this
line. (Note these scopes are the defaults for <code>@indent</code> and <code>@outdent</code>—they are
written explicitly for demonstration.)</p>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>##</a-p> <a-tt>Adding indent queries</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">Helix uses tree-sitter to correctly indent new lines. This requires a tree-</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">sitter grammar and an `indent.scm` query file placed in `runtime/queries/</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">{language}/indents.scm`. The indentation for a line is calculated by traversing</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">the syntax tree from the lowest node at the beginning of the new line (see</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">[Indent queries](#indent-queries)). Each of these nodes contributes to the total</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text">indent when it is captured by the query (in what way depends on the name of</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text">the capture.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">Note that it matters where these added indents begin. For example,</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">multiple indent level increases that start on the same line only increase</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text">the total indent level by 1. See [Capture types](#capture-types).</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text">By default, Helix uses the `hybrid` indentation heuristic. This means that</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text">indent queries are not used to compute the expected absolute indentation of a</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text">line but rather the expected difference in indentation between the new and an</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text">already existing line. This difference is then added to the actual indentation</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text">of the already existing line. Since this makes errors in the indent queries</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text">harder to find, it is recommended to disable it when testing via</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text">`:set indent-heuristic tree-sitter`. The rest of this guide assumes that</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text">the `tree-sitter` heuristic is used.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"><a-p>##</a-p> <a-tt>Indent queries</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text">When Helix is inserting a new line through `o`, `O`, or `&lt;ret&gt;`, to determine</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text">the indent level for the new line, the query in `indents.scm` is run on the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text">document. The starting position of the query is the end of the line above where</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text">a new line will be inserted.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text">For `o`, the inserted line is the line below the cursor, so that starting</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text">position of the query is the end of the current line.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"><a-p>```</a-p><a-tl>rust</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>fn </a-p><a-f>need_hero</a-f><a-p>(</a-p><a-v>some_hero</a-v><a-p>: </a-p><a-t>Hero</a-t><a-p>, </a-p><a-v>life</a-v><a-p>: </a-p><a-t>Life</a-t><a-p>) -&gt; {</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>    </a-p><a-m>matches!</a-m><a-p>(some_hero, </a-p><a-cr>Hero</a-cr><a-p> { </a-p><a-c>// ←─────────────────╮</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"><a-p>        </a-p><a-pr>strong</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,</a-p><a-c>//←╮  ↑  ↑                     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>        </a-p><a-pr>fast</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>// │  │  ╰── query start       │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>        </a-p><a-pr>sure</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>// │  ╰───── cursor            ├─ traversal </a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"><a-p>        </a-p><a-pr>soon</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>// ╰──────── new line inserted │  start node</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>    }) &amp;&amp;            </a-p><a-c>//                             │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>//  ↑                                               │</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"><a-p>//  ╰───────────────────────────────────────────────╯</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"><a-p>    some_hero &gt; life</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"><a-p>}</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"><a-p>For `O`, the newly inserted line is the *current* line, so the starting position</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>of the query is the end of the line above the cursor.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>```</a-p><a-tl>rust</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text"><a-p>fn </a-p><a-f>need_hero</a-f><a-p>(</a-p><a-v>some_hero</a-v><a-p>: </a-p><a-t>Hero</a-t><a-p>, </a-p><a-v>life</a-v><a-p>: </a-p><a-t>Life</a-t><a-p>) -&gt; { </a-p><a-c>// ←─╮</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text"><a-p>    </a-p><a-m>matches!</a-m><a-p>(some_hero, </a-p><a-cr>Hero</a-cr><a-p> { </a-p><a-c>// ←╮          ↑     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L54" href="#L54">54</a><span class="code-text"><a-p>        </a-p><a-pr>strong</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,</a-p><a-c>//    ↑   ╭───╯          │     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L55" href="#L55">55</a><span class="code-text"><a-p>        </a-p><a-pr>fast</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>//    │   │ query start ─╯     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L56" href="#L56">56</a><span class="code-text"><a-p>        </a-p><a-pr>sure</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>//    ╰───┼ cursor             ├─ traversal</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L57" href="#L57">57</a><span class="code-text"><a-p>        </a-p><a-pr>soon</a-pr><a-p>: </a-p><a-co>true</a-co><a-p>,  </a-p><a-c>//        ╰ new line inserted  │  start node</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L58" href="#L58">58</a><span class="code-text"><a-p>    }) &amp;&amp;            </a-p><a-c>//                             │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L59" href="#L59">59</a><span class="code-text"><a-p>    some_hero &gt; life </a-p><a-c>//                             │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L60" href="#L60">60</a><span class="code-text"><a-p>} </a-p><a-c>// ←──────────────────────────────────────────────╯</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L61" href="#L61">61</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L62" href="#L62">62</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L63" href="#L63">63</a><span class="code-text"><a-p>From this starting node, the syntax tree is traversed up until the root node.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L64" href="#L64">64</a><span class="code-text"><a-p>Each indent capture is collected along the way, and then combined according to</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L65" href="#L65">65</a><span class="code-text"><a-p>their [capture types](#capture-types) and [scopes](#scopes) to a final indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L66" href="#L66">66</a><span class="code-text"><a-p>level for the line.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L67" href="#L67">67</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L68" href="#L68">68</a><span class="code-text"><a-p>### </a-p><a-tt>Capture types</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L69" href="#L69">69</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L70" href="#L70">70</a><span class="code-text"><a-p>- `@indent` (default scope `tail`):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L71" href="#L71">71</a><span class="code-text"><a-p>  Increase the indent level by 1. Multiple occurrences in the same line *do not*</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L72" href="#L72">72</a><span class="code-text"><a-p>  stack. If there is at least one `@indent` and one `@outdent` capture on the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L73" href="#L73">73</a><span class="code-text"><a-p>  same line, the indent level isn&#39;t changed at all.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L74" href="#L74">74</a><span class="code-text"><a-p>- `@outdent` (default scope `all`):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L75" href="#L75">75</a><span class="code-text"><a-p>  Decrease the indent level by 1. The same rules as for `@indent` apply.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L76" href="#L76">76</a><span class="code-text"><a-p>- `@indent.always` (default scope `tail`):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L77" href="#L77">77</a><span class="code-text"><a-p>  Increase the indent level by 1. Multiple occurrences on the same line *do*</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L78" href="#L78">78</a><span class="code-text"><a-p>  stack. The final indent level is `@indent.always` – `@outdent.always`. If</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L79" href="#L79">79</a><span class="code-text"><a-p>  an `@indent` and an `@indent.always` are on the same line, the `@indent` is</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L80" href="#L80">80</a><span class="code-text"><a-p>  ignored.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L81" href="#L81">81</a><span class="code-text"><a-p>- `@outdent.always` (default scope `all`):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L82" href="#L82">82</a><span class="code-text"><a-p>  Decrease the indent level by 1. The same rules as for `@indent.always` apply.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L83" href="#L83">83</a><span class="code-text"><a-p>- `@align` (default scope `all`):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L84" href="#L84">84</a><span class="code-text"><a-p>  Align everything inside this node to some anchor. The anchor is given</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L85" href="#L85">85</a><span class="code-text"><a-p>  by the start of the node captured by `@anchor` in the same pattern.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L86" href="#L86">86</a><span class="code-text"><a-p>  Every pattern with an `@align` should contain exactly one `@anchor`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L87" href="#L87">87</a><span class="code-text"><a-p>  Indent (and outdent) for nodes below (in terms of their starting line)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L88" href="#L88">88</a><span class="code-text"><a-p>  the `@align` node is added to the indentation required for alignment.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L89" href="#L89">89</a><span class="code-text"><a-p>- `@extend`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L90" href="#L90">90</a><span class="code-text"><a-p>  Extend the range of this node to the end of the line and to lines that are</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L91" href="#L91">91</a><span class="code-text"><a-p>  indented more than the line that this node starts on. This is useful for</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L92" href="#L92">92</a><span class="code-text"><a-p>  languages like Python, where for the purpose of indentation some nodes (like</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L93" href="#L93">93</a><span class="code-text"><a-p>  functions or classes) should also contain indented lines that follow them.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L94" href="#L94">94</a><span class="code-text"><a-p>- `@extend.prevent-once`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L95" href="#L95">95</a><span class="code-text"><a-p>  Prevents the first extension of an ancestor of this node. For example, in Python</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L96" href="#L96">96</a><span class="code-text"><a-p>  a return expression always ends the block that it is in. Note that this only</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L97" href="#L97">97</a><span class="code-text"><a-p>  stops the extension of the next `@extend` capture. If multiple ancestors are</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L98" href="#L98">98</a><span class="code-text"><a-p>  captured, only the extension of the innermost one is prevented. All other</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L99" href="#L99">99</a><span class="code-text"><a-p>  ancestors are unaffected (regardless of whether the innermost ancestor would</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L100" href="#L100">100</a><span class="code-text"><a-p>  actually have been extended).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L101" href="#L101">101</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L102" href="#L102">102</a><span class="code-text"><a-p>#### </a-p><a-tt>`@indent` / `@outdent`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L103" href="#L103">103</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L104" href="#L104">104</a><span class="code-text"><a-p>Consider this example:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L105" href="#L105">105</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L106" href="#L106">106</a><span class="code-text"><a-p>```</a-p><a-tl>rust</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L107" href="#L107">107</a><span class="code-text"><a-p>fn </a-p><a-f>shout</a-f><a-p>(</a-p><a-v>things</a-v><a-p>: </a-p><a-t>Vec</a-t><a-p>&lt;</a-p><a-t>Thing</a-t><a-p>&gt;) {</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L108" href="#L108">108</a><span class="code-text"><a-p>    </a-p><a-c>//                       ↑</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L109" href="#L109">109</a><span class="code-text"><a-p>    </a-p><a-c>//                       ├───────────────────────╮ indent level</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L110" href="#L110">110</a><span class="code-text"><a-p>    </a-p><a-c>//                    @indent                    ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L111" href="#L111">111</a><span class="code-text"><a-p>    </a-p><a-c>//                                               │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L112" href="#L112">112</a><span class="code-text"><a-p>    </a-p><a-k>let</a-k><a-p> it_all = |out| { things.</a-p><a-f>filter</a-f><a-p>(|thing| { </a-p><a-c>//  │      1</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L113" href="#L113">113</a><span class="code-text"><a-p>    </a-p><a-c>//                 ↑                       ↑     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L114" href="#L114">114</a><span class="code-text"><a-p>    </a-p><a-c>//                 ├───────────────────────┼─────┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L115" href="#L115">115</a><span class="code-text"><a-p>    </a-p><a-c>//              @indent                 @indent  │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L116" href="#L116">116</a><span class="code-text"><a-p>    </a-p><a-c>//                                               │      2</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L117" href="#L117">117</a><span class="code-text"><a-p>        thing.</a-p><a-f>can_do_with</a-f><a-p>(out) </a-p><a-c>//                    │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L118" href="#L118">118</a><span class="code-text"><a-p>    })}; </a-p><a-c>//                                          ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L119" href="#L119">119</a><span class="code-text"><a-p>  </a-p><a-c>//↑↑↑                                              │      1</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L120" href="#L120">120</a><span class="code-text"><a-p>} </a-p><a-c>//╰┼┴──────────────────────────────────────────────┴┄┄┄┄┄┄┄┄┄┄┄┄┄┄</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L121" href="#L121">121</a><span class="code-text"><a-p>// 3x @outdent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L122" href="#L122">122</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L123" href="#L123">123</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L124" href="#L124">124</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L125" href="#L125">125</a><span class="code-text"><a-p>((block) @indent)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L126" href="#L126">126</a><span class="code-text"><a-p>[&quot;}&quot; &quot;)&quot;] @outdent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L127" href="#L127">127</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L128" href="#L128">128</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L129" href="#L129">129</a><span class="code-text"><a-p>Note how on the second line, we have two blocks begin on the same line. In this</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L130" href="#L130">130</a><span class="code-text"><a-p>case, since both captures occur on the same line, they are combined and only</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L131" href="#L131">131</a><span class="code-text"><a-p>result in a net increase of 1. Also note that the closing `}`s are part of the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L132" href="#L132">132</a><span class="code-text"><a-p>`@indent` captures, but the 3 `@outdent`s also combine into 1 and result in that</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L133" href="#L133">133</a><span class="code-text"><a-p>line losing one indent level.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L134" href="#L134">134</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L135" href="#L135">135</a><span class="code-text"><a-p>#### </a-p><a-tt>`@extend` / `@extend.prevent-once`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L136" href="#L136">136</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L137" href="#L137">137</a><span class="code-text"><a-p>For an example of where `@extend` can be useful, consider Python, which is</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L138" href="#L138">138</a><span class="code-text"><a-p>whitespace-sensitive.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L139" href="#L139">139</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L140" href="#L140">140</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L141" href="#L141">141</a><span class="code-text"><a-p>]</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L142" href="#L142">142</a><span class="code-text"><a-p>  (parenthesized_expression)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L143" href="#L143">143</a><span class="code-text"><a-p>  (function_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L144" href="#L144">144</a><span class="code-text"><a-p>  (class_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L145" href="#L145">145</a><span class="code-text"><a-p>] @indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L146" href="#L146">146</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L147" href="#L147">147</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L148" href="#L148">148</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L149" href="#L149">149</a><span class="code-text"><a-p>```</a-p><a-tl>python</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L150" href="#L150">150</a><span class="code-text"><a-p>class </a-p><a-cr>Hero</a-cr><a-p>:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L151" href="#L151">151</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>__init__</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>strong</a-v><a-p>, </a-p><a-v>fast</a-v><a-p>, </a-p><a-v>sure</a-v><a-p>, </a-p><a-v>soon</a-v><a-p>):</a-p><a-c>#  ←─╮</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L152" href="#L152">152</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>strong</a-v><a-p> </a-p><a-c>#                     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L153" href="#L153">153</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>fast</a-v><a-p>     </a-p><a-c># ╭─── query start    │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L154" href="#L154">154</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>sure</a-v><a-p>     </a-p><a-c># │ ╭─ cursor         │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L155" href="#L155">155</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>soon</a-v><a-p>     </a-p><a-c># │ │                 │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L156" href="#L156">156</a><span class="code-text"><a-p>        </a-p><a-c>#     ↑            ↑      │ │                 │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L157" href="#L157">157</a><span class="code-text"><a-p>        </a-p><a-c>#     │            ╰──────╯ │                 │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L158" href="#L158">158</a><span class="code-text"><a-p>        </a-p><a-c>#     ╰─────────────────────╯                 │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L159" href="#L159">159</a><span class="code-text"><a-p>        </a-p><a-c>#                                             ├─ traversal</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L160" href="#L160">160</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>need_hero</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>life</a-v><a-p>):         </a-p><a-c>#              │  start node</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L161" href="#L161">161</a><span class="code-text"><a-p>        </a-p><a-k>return</a-k><a-p> (                       </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L162" href="#L162">162</a><span class="code-text"><a-p>            </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr><a-p>             </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L163" href="#L163">163</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr><a-p>           </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L164" href="#L164">164</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr><a-p>           </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L165" href="#L165">165</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr><a-p>           </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L166" href="#L166">166</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p> </a-p><a-o>&gt;</a-o><a-p> </a-p><a-v>life</a-v><a-p>            </a-p><a-c>#              │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L167" href="#L167">167</a><span class="code-text"><a-p>        ) </a-p><a-c># ←─────────────────────────────────────────╯</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L168" href="#L168">168</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L169" href="#L169">169</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L170" href="#L170">170</a><span class="code-text"><a-p>Without braces to catch the scope of the function, the smallest descendant of</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L171" href="#L171">171</a><span class="code-text"><a-p>the cursor on a line feed ends up being the entire inside of the class. Because</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L172" href="#L172">172</a><span class="code-text"><a-p>of this, it will miss the entire function node and its indent capture, leading</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L173" href="#L173">173</a><span class="code-text"><a-p>to an indent level one too small.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L174" href="#L174">174</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L175" href="#L175">175</a><span class="code-text"><a-p>To address this case, `@extend` tells helix to &quot;extend&quot; the captured node&#39;s span</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L176" href="#L176">176</a><span class="code-text"><a-p>to the line feed and every consecutive line that has a greater indent level than</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L177" href="#L177">177</a><span class="code-text"><a-p>the line of the node.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L178" href="#L178">178</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L179" href="#L179">179</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L180" href="#L180">180</a><span class="code-text"><a-p>(parenthesized_expression) @indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L181" href="#L181">181</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L182" href="#L182">182</a><span class="code-text"><a-p>]</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L183" href="#L183">183</a><span class="code-text"><a-p>  (function_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L184" href="#L184">184</a><span class="code-text"><a-p>  (class_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L185" href="#L185">185</a><span class="code-text"><a-p>] @indent @extend</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L186" href="#L186">186</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L187" href="#L187">187</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L188" href="#L188">188</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L189" href="#L189">189</a><span class="code-text"><a-p>```</a-p><a-tl>python</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L190" href="#L190">190</a><span class="code-text"><a-p>class </a-p><a-cr>Hero</a-cr><a-p>:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L191" href="#L191">191</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>__init__</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>strong</a-v><a-p>, </a-p><a-v>fast</a-v><a-p>, </a-p><a-v>sure</a-v><a-p>, </a-p><a-v>soon</a-v><a-p>):</a-p><a-c>#  ←─╮</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L192" href="#L192">192</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>strong</a-v><a-p> </a-p><a-c>#                     │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L193" href="#L193">193</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>fast</a-v><a-p>     </a-p><a-c># ╭─── query start    ├─ traversal</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L194" href="#L194">194</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>sure</a-v><a-p>     </a-p><a-c># │ ╭─ cursor         │  start node</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L195" href="#L195">195</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>soon</a-v><a-p>     </a-p><a-c># │ │ ←───────────────╯</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L196" href="#L196">196</a><span class="code-text"><a-p>        </a-p><a-c>#     ↑            ↑      │ │                 </a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L197" href="#L197">197</a><span class="code-text"><a-p>        </a-p><a-c>#     │            ╰──────╯ │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L198" href="#L198">198</a><span class="code-text"><a-p>        </a-p><a-c>#     ╰─────────────────────╯</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L199" href="#L199">199</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>need_hero</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>life</a-v><a-p>):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L200" href="#L200">200</a><span class="code-text"><a-p>        </a-p><a-k>return</a-k><a-p> (</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L201" href="#L201">201</a><span class="code-text"><a-p>            </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L202" href="#L202">202</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L203" href="#L203">203</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L204" href="#L204">204</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L205" href="#L205">205</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p> </a-p><a-o>&gt;</a-o><a-p> </a-p><a-v>life</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L206" href="#L206">206</a><span class="code-text"><a-p>        )</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L207" href="#L207">207</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L208" href="#L208">208</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L209" href="#L209">209</a><span class="code-text"><a-p>Furthermore, there are some cases where extending to everything with a greater</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L210" href="#L210">210</a><span class="code-text"><a-p>indent level may not be desirable. Consider the `need_hero` function above. If</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L211" href="#L211">211</a><span class="code-text"><a-p>our cursor is on the last line of the returned expression.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L212" href="#L212">212</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L213" href="#L213">213</a><span class="code-text"><a-p>```</a-p><a-tl>python</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L214" href="#L214">214</a><span class="code-text"><a-p>class </a-p><a-cr>Hero</a-cr><a-p>:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L215" href="#L215">215</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>__init__</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>strong</a-v><a-p>, </a-p><a-v>fast</a-v><a-p>, </a-p><a-v>sure</a-v><a-p>, </a-p><a-v>soon</a-v><a-p>):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L216" href="#L216">216</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>strong</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L217" href="#L217">217</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>fast</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L218" href="#L218">218</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>sure</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L219" href="#L219">219</a><span class="code-text"><a-p>        </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr><a-p> </a-p><a-o>=</a-o><a-p> </a-p><a-v>soon</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L220" href="#L220">220</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L221" href="#L221">221</a><span class="code-text"><a-p>    </a-p><a-k>def</a-k><a-p> </a-p><a-f>need_hero</a-f><a-p>(</a-p><a-v>self</a-v><a-p>, </a-p><a-v>life</a-v><a-p>):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L222" href="#L222">222</a><span class="code-text"><a-p>        </a-p><a-k>return</a-k><a-p> (</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L223" href="#L223">223</a><span class="code-text"><a-p>            </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_strong</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L224" href="#L224">224</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_fast</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L225" href="#L225">225</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_sure</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L226" href="#L226">226</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p>.</a-p><a-pr>is_soon</a-pr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L227" href="#L227">227</a><span class="code-text"><a-p>            </a-p><a-o>and</a-o><a-p> </a-p><a-v>self</a-v><a-p> </a-p><a-o>&gt;</a-o><a-p> </a-p><a-v>life</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L228" href="#L228">228</a><span class="code-text"><a-p>        ) </a-p><a-c># ←─── cursor</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L229" href="#L229">229</a><span class="code-text"><a-p>    </a-p><a-c>#←────────── where cursor should go on new line</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L230" href="#L230">230</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L231" href="#L231">231</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L232" href="#L232">232</a><span class="code-text"><a-p>In Python, the are a few tokens that will always end a scope, such as a return</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L233" href="#L233">233</a><span class="code-text"><a-p>statement. Since the scope ends, so should the indent level. But because the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L234" href="#L234">234</a><span class="code-text"><a-p>function span is extended to every line with a greater indent level, a new line</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L235" href="#L235">235</a><span class="code-text"><a-p>would just continue on the same level. And an `@outdent` would not help us here</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L236" href="#L236">236</a><span class="code-text"><a-p>either, since it would cause everything in the parentheses to become outdented</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L237" href="#L237">237</a><span class="code-text"><a-p>as well.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L238" href="#L238">238</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L239" href="#L239">239</a><span class="code-text"><a-p>To help, we need to signal an end to the extension. We can do this with</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L240" href="#L240">240</a><span class="code-text"><a-p>`@extend.prevent-once`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L241" href="#L241">241</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L242" href="#L242">242</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L243" href="#L243">243</a><span class="code-text"><a-p>(parenthesized_expression) @indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L244" href="#L244">244</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L245" href="#L245">245</a><span class="code-text"><a-p>]</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L246" href="#L246">246</a><span class="code-text"><a-p>  (function_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L247" href="#L247">247</a><span class="code-text"><a-p>  (class_definition)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L248" href="#L248">248</a><span class="code-text"><a-p>] @indent @extend</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L249" href="#L249">249</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L250" href="#L250">250</a><span class="code-text"><a-p>(return_statement) @extend.prevent-once</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L251" href="#L251">251</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L252" href="#L252">252</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L253" href="#L253">253</a><span class="code-text"><a-p>#### </a-p><a-tt>`@indent.always` / `@outdent.always`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L254" href="#L254">254</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L255" href="#L255">255</a><span class="code-text"><a-p>As mentioned before, normally if there is more than one `@indent` or `@outdent`</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L256" href="#L256">256</a><span class="code-text"><a-p>capture on the same line, they are combined.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L257" href="#L257">257</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L258" href="#L258">258</a><span class="code-text"><a-p>Sometimes, there are cases when you may want to ensure that every indent capture</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L259" href="#L259">259</a><span class="code-text"><a-p>is additive, regardless of how many occur on the same line. Consider this</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L260" href="#L260">260</a><span class="code-text"><a-p>example in YAML.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L261" href="#L261">261</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L262" href="#L262">262</a><span class="code-text"><a-p>```</a-p><a-tl>yaml</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L263" href="#L263">263</a><span class="code-text"><a-p>  - </a-p><a-pr>foo</a-pr><a-p>: </a-p><a-s>bar</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L264" href="#L264">264</a><span class="code-text"><a-p># ↑ ↑</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L265" href="#L265">265</a><span class="code-text"><a-p># │ ╰─────────────── start of map</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L266" href="#L266">266</a><span class="code-text"><a-p># ╰───────────────── start of list element</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L267" href="#L267">267</a><span class="code-text"><a-p>    </a-p><a-pr>baz</a-pr><a-p>: </a-p><a-s>quux</a-s><a-p> </a-p><a-c># ←─── cursor</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L268" href="#L268">268</a><span class="code-text"><a-p>    </a-p><a-c># ←───────────── where the cursor should go on a new line</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L269" href="#L269">269</a><span class="code-text"><a-p>    </a-p><a-pr>garply</a-pr><a-p>: </a-p><a-s>waldo</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L270" href="#L270">270</a><span class="code-text"><a-p>  - </a-p><a-pr>quux</a-pr><a-p>:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L271" href="#L271">271</a><span class="code-text"><a-p>      </a-p><a-pr>bar</a-pr><a-p>: </a-p><a-s>baz</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L272" href="#L272">272</a><span class="code-text"><a-p>    </a-p><a-pr>xyzzy</a-pr><a-p>: </a-p><a-s>thud</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L273" href="#L273">273</a><span class="code-text"><a-p>    </a-p><a-pr>fred</a-pr><a-p>: </a-p><a-s>plugh</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L274" href="#L274">274</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L275" href="#L275">275</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L276" href="#L276">276</a><span class="code-text"><a-p>In YAML, you often have lists of maps. In these cases, the syntax is such that</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L277" href="#L277">277</a><span class="code-text"><a-p>the list element and the map both start on the same line. But we really do want</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L278" href="#L278">278</a><span class="code-text"><a-p>to start an indentation for each of these so that subsequent keys in the map</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L279" href="#L279">279</a><span class="code-text"><a-p>hang over the list and align properly. This is where `@indent.always` helps.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L280" href="#L280">280</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L281" href="#L281">281</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L282" href="#L282">282</a><span class="code-text"><a-p>((block_sequence_item) @item @indent.always @extend</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L283" href="#L283">283</a><span class="code-text"><a-p>  (#not-one-line? @item))</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L284" href="#L284">284</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L285" href="#L285">285</a><span class="code-text"><a-p>((block_mapping_pair</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L286" href="#L286">286</a><span class="code-text"><a-p>    key: (_) @key</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L287" href="#L287">287</a><span class="code-text"><a-p>    value: (_) @val</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L288" href="#L288">288</a><span class="code-text"><a-p>    (#not-same-line? @key @val)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L289" href="#L289">289</a><span class="code-text"><a-p>  ) @indent.always @extend</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L290" href="#L290">290</a><span class="code-text"><a-p>)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L291" href="#L291">291</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L292" href="#L292">292</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L293" href="#L293">293</a><span class="code-text"><a-p>## </a-p><a-tt>Predicates</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L294" href="#L294">294</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L295" href="#L295">295</a><span class="code-text"><a-p>In some cases, an S-expression cannot express exactly what pattern should be matched.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L296" href="#L296">296</a><span class="code-text"><a-p>For that, tree-sitter allows for predicates to appear anywhere within a pattern,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L297" href="#L297">297</a><span class="code-text"><a-p>similar to how `#set!` declarations work:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L298" href="#L298">298</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L299" href="#L299">299</a><span class="code-text"><a-p>```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L300" href="#L300">300</a><span class="code-text"><a-p>(some_kind</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L301" href="#L301">301</a><span class="code-text"><a-p>  (child_kind) @indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L302" href="#L302">302</a><span class="code-text"><a-p>  (#predicate? arg1 arg2 ...)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L303" href="#L303">303</a><span class="code-text"><a-p>)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L304" href="#L304">304</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L305" href="#L305">305</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L306" href="#L306">306</a><span class="code-text"><a-p>The number of arguments depends on the predicate that&#39;s used.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L307" href="#L307">307</a><span class="code-text"><a-p>Each argument is either a capture (`@name`) or a string (`&quot;some string&quot;`).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L308" href="#L308">308</a><span class="code-text"><a-p>The following predicates are supported by tree-sitter:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L309" href="#L309">309</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L310" href="#L310">310</a><span class="code-text"><a-p>- `#eq?`/`#not-eq?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L311" href="#L311">311</a><span class="code-text"><a-p>The first argument (a capture) must/must not be equal to the second argument</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L312" href="#L312">312</a><span class="code-text"><a-p>(a capture or a string).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L313" href="#L313">313</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L314" href="#L314">314</a><span class="code-text"><a-p>- `#match?`/`#not-match?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L315" href="#L315">315</a><span class="code-text"><a-p>The first argument (a capture) must/must not match the regex given in the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L316" href="#L316">316</a><span class="code-text"><a-p>second argument (a string).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L317" href="#L317">317</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L318" href="#L318">318</a><span class="code-text"><a-p>- `#any-of?`/`#not-any-of?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L319" href="#L319">319</a><span class="code-text"><a-p>The first argument (a capture) must/must not be one of the other arguments</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L320" href="#L320">320</a><span class="code-text"><a-p>(strings).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L321" href="#L321">321</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L322" href="#L322">322</a><span class="code-text"><a-p>Additionally, we support some custom predicates for indent queries:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L323" href="#L323">323</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L324" href="#L324">324</a><span class="code-text"><a-p>- `#not-kind-eq?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L325" href="#L325">325</a><span class="code-text"><a-p>The kind of the first argument (a capture) must not be equal to the second</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L326" href="#L326">326</a><span class="code-text"><a-p>argument (a string).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L327" href="#L327">327</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L328" href="#L328">328</a><span class="code-text"><a-p>- `#same-line?`/`#not-same-line?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L329" href="#L329">329</a><span class="code-text"><a-p>The captures given by the 2 arguments must/must not start on the same line.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L330" href="#L330">330</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L331" href="#L331">331</a><span class="code-text"><a-p>- `#one-line?`/`#not-one-line?`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L332" href="#L332">332</a><span class="code-text"><a-p>The captures given by the fist argument must/must span a total of one line.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L333" href="#L333">333</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L334" href="#L334">334</a><span class="code-text"><a-p>### </a-p><a-tt>Scopes</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L335" href="#L335">335</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L336" href="#L336">336</a><span class="code-text"><a-p>Added indents don&#39;t always apply to the whole node. For example, in most</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L337" href="#L337">337</a><span class="code-text"><a-p>cases when a node should be indented, we actually only want everything</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L338" href="#L338">338</a><span class="code-text"><a-p>except for its first line to be indented. For this, there are several</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L339" href="#L339">339</a><span class="code-text"><a-p>scopes (more scopes may be added in the future if required):</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L340" href="#L340">340</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L341" href="#L341">341</a><span class="code-text"><a-p>- `tail`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L342" href="#L342">342</a><span class="code-text"><a-p>This scope applies to everything except for the first line of the</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L343" href="#L343">343</a><span class="code-text"><a-p>captured node.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L344" href="#L344">344</a><span class="code-text"><a-p>- `all`:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L345" href="#L345">345</a><span class="code-text"><a-p>This scope applies to the whole captured node. This is only different from</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L346" href="#L346">346</a><span class="code-text"><a-p>`tail` when the captured node is the first node on its line.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L347" href="#L347">347</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L348" href="#L348">348</a><span class="code-text"><a-p>For example, imagine we have the following function</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L349" href="#L349">349</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L350" href="#L350">350</a><span class="code-text"><a-p>```</a-p><a-tl>rust</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L351" href="#L351">351</a><span class="code-text"><a-p>fn </a-p><a-f>aha</a-f><a-p>() { </a-p><a-c>// ←─────────────────────────────────────╮</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L352" href="#L352">352</a><span class="code-text"><a-p>  </a-p><a-k>let</a-k><a-p> take = </a-p><a-s>&quot;on me&quot;</a-s><a-p>;  </a-p><a-c>// ←──────────────╮  scope:  │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L353" href="#L353">353</a><span class="code-text"><a-p>  </a-p><a-k>let</a-k><a-p> take = </a-p><a-s>&quot;me on&quot;</a-s><a-p>;             </a-p><a-c>//     ├─ &quot;tail&quot;  ├─ (block) @indent</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L354" href="#L354">354</a><span class="code-text"><a-p>  </a-p><a-k>let</a-k><a-p> ill = </a-p><a-f>be_gone_days</a-f><a-p>(</a-p><a-co>1</a-co><a-p> || </a-p><a-co>2</a-co><a-p>); </a-p><a-c>//     │          │</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L355" href="#L355">355</a><span class="code-text"><a-p>} </a-p><a-c>// ←───────────────────────────────────┴──────────┴─ &quot;}&quot; @outdent</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L356" href="#L356">356</a><span class="code-text"><a-p>                                         </a-p><a-c>//                scope: &quot;all&quot;</a-c></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L357" href="#L357">357</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L358" href="#L358">358</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L359" href="#L359">359</a><span class="code-text"><a-p>We can write the following query with the `#set!` declaration:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L360" href="#L360">360</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L361" href="#L361">361</a><span class="code-text"><a-p>  ```</a-p><a-tl>scm</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L362" href="#L362">362</a><span class="code-text"><a-p>  ((block) @indent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L363" href="#L363">363</a><span class="code-text"><a-p>   (#set! &quot;scope&quot; &quot;tail&quot;))</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L364" href="#L364">364</a><span class="code-text"><a-p>  (&quot;}&quot; @outdent</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L365" href="#L365">365</a><span class="code-text"><a-p>   (#set! &quot;scope&quot; &quot;all&quot;))</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L366" href="#L366">366</a><span class="code-text"><a-p>  ```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L367" href="#L367">367</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L368" href="#L368">368</a><span class="code-text">As we can see, the &quot;tail&quot; scope covers the node, except for the first line.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L369" href="#L369">369</a><span class="code-text">Everything up to and including the closing brace gets an indent level of 1.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L370" href="#L370">370</a><span class="code-text">Then, on the closing brace, we encounter an outdent with a scope of &quot;all&quot;, which</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L371" href="#L371">371</a><span class="code-text">means the first line is included, and the indent level is cancelled out on this</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L372" href="#L372">372</a><span class="code-text">line. (Note these scopes are the defaults for `@indent` and `@outdent`—they are</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L373" href="#L373">373</a><span class="code-text">written explicitly for demonstration.)</span></span></pre></div></div>
</main>
</body>
</html>
