diff options
Diffstat (limited to 'guides')
-rw-r--r-- | guides/indent.html | 37 | ||||
-rw-r--r-- | guides/injection.html | 6 | ||||
-rw-r--r-- | guides/rainbow_bracket_queries.html | 6 | ||||
-rw-r--r-- | guides/textobject.html | 2 |
4 files changed, 34 insertions, 17 deletions
diff --git a/guides/indent.html b/guides/indent.html index a968f7bb..25be199a 100644 --- a/guides/indent.html +++ b/guides/indent.html @@ -189,6 +189,14 @@ 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 id="indent-queries"><a class="header" href="#indent-queries">Indent queries</a></h2> <p>When Helix is inserting a new line through <code>o</code>, <code>O</code>, or <code><ret></code>, to determine the indent level for the new line, the query in <code>indents.scm</code> is run on the @@ -283,7 +291,7 @@ actually have been extended).</li> // 3x @outdent <span class="boring">}</span></code></pre></pre> <pre><code class="language-scm">((block) @indent) -["}" ")"] @outdent +["}" ")"] @outdent </code></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 @@ -323,7 +331,7 @@ whitespace-sensitive.</p> 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 +<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><code class="language-scm">(parenthesized_expression) @indent @@ -431,7 +439,7 @@ similar to how <code>#set!</code> declarations work:</p> ) </code></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>). +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> @@ -444,6 +452,11 @@ The first argument (a capture) must/must not be equal to the second argument 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> @@ -478,21 +491,21 @@ This scope applies to the whole captured node. This is only different from <pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] </span><span class="boring">fn main() { </span>fn aha() { // ←─────────────────────────────────────╮ - let take = "on me"; // ←──────────────╮ scope: │ - let take = "me on"; // ├─ "tail" ├─ (block) @indent + let take = "on me"; // ←──────────────╮ scope: │ + let take = "me on"; // ├─ "tail" ├─ (block) @indent let ill = be_gone_days(1 || 2); // │ │ -} // ←───────────────────────────────────┴──────────┴─ "}" @outdent - // scope: "all" +} // ←───────────────────────────────────┴──────────┴─ "}" @outdent + // scope: "all" <span class="boring">}</span></code></pre></pre> <p>We can write the following query with the <code>#set!</code> declaration:</p> <pre><code class="language-scm">((block) @indent - (#set! "scope" "tail")) -("}" @outdent - (#set! "scope" "all")) + (#set! "scope" "tail")) +("}" @outdent + (#set! "scope" "all")) </code></pre> -<p>As we can see, the "tail" scope covers the node, except for the first line. +<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 +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> diff --git a/guides/injection.html b/guides/injection.html index fb4bb8f3..f4fe238b 100644 --- a/guides/injection.html +++ b/guides/injection.html @@ -185,7 +185,7 @@ In addition to the <a href="http://tree-sitter.github.io/tree-sitter/syntax-high are a few Helix specific extensions that allow for more control.</p> <p>And example of a simple query that would highlight all strings as bash in Nix:</p> <pre><code class="language-scm">((string_expression (string_fragment) @injection.content) - (#set! injection.language "bash")) + (#set! injection.language "bash")) </code></pre> <h2 id="capture-types"><a class="header" href="#capture-types">Capture Types</a></h2> <ul> @@ -243,6 +243,10 @@ The first argument (a capture) must be equal to the second argument The first argument (a capture) must match the regex given in the second argument (a string).</p> </li> +<li> +<p><code>#any-of?</code> (standard): +The first argument (a capture) must be one of the other arguments (strings).</p> +</li> </ul> </main> diff --git a/guides/rainbow_bracket_queries.html b/guides/rainbow_bracket_queries.html index 98f11d99..c64d737c 100644 --- a/guides/rainbow_bracket_queries.html +++ b/guides/rainbow_bracket_queries.html @@ -196,7 +196,7 @@ language itself. These queries will go into a <code>runtime/queries/tsq/rainbows.scm</code> file in the repository root.</p> <p>First we'll add the <code>@rainbow.bracket</code> captures. TSQ only has parentheses and square brackets:</p> -<pre><code class="language-tsq">["(" ")" "[" "]"] @rainbow.bracket +<pre><code class="language-tsq">["(" ")" "[" "]"] @rainbow.bracket </code></pre> <p>The ordering of the nodes within the alternation (square brackets) is not taken into consideration.</p> @@ -207,7 +207,7 @@ names of rules in the grammar. Brackets are usually written in tree-sitter grammars as literal strings, for example:</p> <pre><code class="language-js">{ // ... - arguments: seq("(", repeat($.argument), ")"), + arguments: seq("(", repeat($.argument), ")"), // ... } </code></pre> @@ -254,7 +254,7 @@ indirect descendants of some node captured with <code>@rainbow.scope</code>.</p> </code></pre> <p>If we want to highlight the <code><</code>, <code>></code> and <code></</code> nodes with rainbow colors, we capture them as <code>@rainbow.bracket</code>:</p> -<pre><code class="language-tsq">["<" ">" "</"] @rainbow.bracket +<pre><code class="language-tsq">["<" ">" "</"] @rainbow.bracket </code></pre> <p>And we capture <code>(element)</code> as <code>@rainbow.scope</code> because <code>(element)</code> nodes nest within each other: they increment the nesting level and switch to the next diff --git a/guides/textobject.html b/guides/textobject.html index a47fd8a6..d67f0dda 100644 --- a/guides/textobject.html +++ b/guides/textobject.html @@ -203,7 +203,7 @@ for example).</p> <tr><td><code>comment.around</code></td></tr> </tbody></table> </div> -<p><a href="https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+filename%3Atextobjects.scm&type=Code&ref=advsearch&l=&l=">Example query files</a> can be found in the helix GitHub repository.</p> +<p><a href="https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+path%3A%2A%2A/textobjects.scm&type=Code&ref=advsearch&l=&l=">Example query files</a> can be found in the helix GitHub repository.</p> <h2 id="queries-for-textobject-based-navigation"><a class="header" href="#queries-for-textobject-based-navigation">Queries for textobject based navigation</a></h2> <p>Tree-sitter based navigation in Helix is done using captures in the following order:</p> |