From e398c24ba19948727affdc6a29254ac69a6b7699 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 03:35:02 -0300 Subject: syntax: helix's indents.scm vendored beside each grammar's textobjects.scm and embedded the same way (zig's adapted to this grammar's node names, rust's \A regexes written with ^, erlang's left out as it does not compile here), compiled when first asked for as a Lazy beside the textobjects, so a new line can take its indent from the tree Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- vendor/queries/README.md | 15 ++- vendor/queries/bash/indents.scm | 23 +++++ vendor/queries/c/indents.scm | 58 ++++++++++++ vendor/queries/c_sharp/indents.scm | 20 ++++ vendor/queries/clojure/indents.scm | 65 +++++++++++++ vendor/queries/cpp/indents.scm | 63 +++++++++++++ vendor/queries/css/indents.scm | 12 +++ vendor/queries/elixir/indents.scm | 27 ++++++ vendor/queries/fortran/indents.scm | 36 ++++++++ vendor/queries/go/indents.scm | 55 +++++++++++ vendor/queries/html/indents.scm | 20 ++++ vendor/queries/java/indents.scm | 53 +++++++++++ vendor/queries/javascript/indents.scm | 72 +++++++++++++++ vendor/queries/json/indents.scm | 14 +++ vendor/queries/kotlin/indents.scm | 51 +++++++++++ vendor/queries/ocaml/indents.scm | 27 ++++++ vendor/queries/php/indents.scm | 34 +++++++ vendor/queries/python/indents.scm | 98 ++++++++++++++++++++ vendor/queries/ruby/indents.scm | 32 +++++++ vendor/queries/rust/indents.scm | 166 ++++++++++++++++++++++++++++++++++ vendor/queries/scala/indents.scm | 29 ++++++ vendor/queries/zig/indents.scm | 22 +++++ 22 files changed, 991 insertions(+), 1 deletion(-) create mode 100644 vendor/queries/bash/indents.scm create mode 100644 vendor/queries/c/indents.scm create mode 100644 vendor/queries/c_sharp/indents.scm create mode 100644 vendor/queries/clojure/indents.scm create mode 100644 vendor/queries/cpp/indents.scm create mode 100644 vendor/queries/css/indents.scm create mode 100644 vendor/queries/elixir/indents.scm create mode 100644 vendor/queries/fortran/indents.scm create mode 100644 vendor/queries/go/indents.scm create mode 100644 vendor/queries/html/indents.scm create mode 100644 vendor/queries/java/indents.scm create mode 100644 vendor/queries/javascript/indents.scm create mode 100644 vendor/queries/json/indents.scm create mode 100644 vendor/queries/kotlin/indents.scm create mode 100644 vendor/queries/ocaml/indents.scm create mode 100644 vendor/queries/php/indents.scm create mode 100644 vendor/queries/python/indents.scm create mode 100644 vendor/queries/ruby/indents.scm create mode 100644 vendor/queries/rust/indents.scm create mode 100644 vendor/queries/scala/indents.scm create mode 100644 vendor/queries/zig/indents.scm (limited to 'vendor') diff --git a/vendor/queries/README.md b/vendor/queries/README.md index 082f4e6b..2977e1cc 100644 --- a/vendor/queries/README.md +++ b/vendor/queries/README.md @@ -1,4 +1,4 @@ -# Textobject queries +# Textobject and indent queries `/textobjects.scm` is helix's own query for that grammar, vendored from helix (https://github.com/helix-editor/helix) at 278b24389, the @@ -16,3 +16,16 @@ them), and erlang, whose helix query does not compile against the grammar version pardes builds. Those grammars have no textobjects, and the keys do nothing there, as in helix without a query. + +`/indents.scm` is helix's indent query for that grammar, vendored +the same way from the same commit, for src/indent.zig: the indent a new line +takes on Enter, `o` and `O`. Vendored for bash, c, c_sharp, clojure, cpp +(with c's inlined), css, elixir, fortran, go, html, java, javascript (ecma's +inlined), json, kotlin, ocaml, php, python, ruby, rust, scala and zig. +`zig/indents.scm` is MODIFIED for this zig grammar's node names, and +`rust/indents.scm` writes its three `#match?` regexes with `^` where helix's +open with `\A`, which mvzr does not know; their headers say so. Not vendored: +ada, haskell, markdown, pascal, powershell and typst (helix has no indent +query for them), and erlang, whose query does not compile against the +grammar version pardes builds. A file of those keeps acme's autoindent, the +line's own indent as it is. diff --git a/vendor/queries/bash/indents.scm b/vendor/queries/bash/indents.scm new file mode 100644 index 00000000..5ca59a57 --- /dev/null +++ b/vendor/queries/bash/indents.scm @@ -0,0 +1,23 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/bash/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (function_definition) + (if_statement) + (for_statement) + (while_statement) + (case_statement) + (case_item) + (pipeline) +] @indent + +[ + "}" + "fi" + "elif" + "else" + "done" + "esac" +] @outdent diff --git a/vendor/queries/c/indents.scm b/vendor/queries/c/indents.scm new file mode 100644 index 00000000..0ed0b66d --- /dev/null +++ b/vendor/queries/c/indents.scm @@ -0,0 +1,58 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/c/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (compound_statement) + (declaration_list) + (field_declaration_list) + (enumerator_list) + (parameter_list) + (init_declarator) + (expression_statement) +] @indent + +[ + "case" + "default" + "}" + "]" + ")" +] @outdent + +; Single statement after if/while/for/do without braces. Capture the body child +; naturally; on a typed newline the engine descends into it (no wrapper trick). +(if_statement + consequence: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(while_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(do_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(for_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) + +(parameter_list + . (parameter_declaration) @anchor + ) @align +(argument_list + . (_) @anchor + ) @align +; These are a bit opinionated since some people just indent binary/ternary expressions spanning multiple lines. +; Since they are only triggered when a newline is inserted into an already complete binary/ternary expression, +; this should happen rarely, so it is not a big deal either way. +; Additionally, adding these queries has the advantage of preventing such continuation lines from being used +; as the baseline when the `hybrid` indent heuristic is used (which is desirable since their indentation is so inconsistent). +(binary_expression + ) @anchor @align +(conditional_expression + "?" @anchor + ) @align diff --git a/vendor/queries/c_sharp/indents.scm b/vendor/queries/c_sharp/indents.scm new file mode 100644 index 00000000..bf875d4b --- /dev/null +++ b/vendor/queries/c_sharp/indents.scm @@ -0,0 +1,20 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/c-sharp/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (declaration_list) + (block) + (enum_member_declaration_list) + (accessor_list) + (switch_body) + (switch_section) + (initializer_expression) +] @indent + +[ + "}" + ")" + "]" +] @outdent diff --git a/vendor/queries/clojure/indents.scm b/vendor/queries/clojure/indents.scm new file mode 100644 index 00000000..5c232fc9 --- /dev/null +++ b/vendor/queries/clojure/indents.scm @@ -0,0 +1,65 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/clojure/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +; If a list has 2 elements on the first line, align to the second element. +; Exclude literals and special keywords that have different indentation rules. +(list_lit . (_) @first . (_) @anchor + (#same-line? @first @anchor) + + (#not-kind-eq? @first "bool_lit") + (#not-kind-eq? @first "nil_lit") + (#not-kind-eq? @first "str_lit") + (#not-kind-eq? @first "num_lit") + (#not-kind-eq? @first "kwd_lit") + (#not-match? @first "^(def|defn|defn-|defmacro|defmethod|defmulti|defonce|defprotocol|deftype|defrecord|defstruct|definline|definterface|deftest|ns|let|letfn|binding|loop|for|doseq|dotimes|when-let|if-let|when-some|if-some|with-.*|fn)$")) @align + +; If the first element in a list is also a list and on a line by itself, +; the outer list is aligned to it +(list_lit . (list_lit) @anchor . + ) @align + +(list_lit . (list_lit) @anchor . (_) @second + (#not-same-line? @anchor @second) + ) @align + +; If the first element in a list is not a list and on a line by itself, +; indent the list body by one level +(list_lit . (_) @first . + (#not-kind-eq? @first "bool_lit") + (#not-kind-eq? @first "nil_lit") + (#not-kind-eq? @first "str_lit") + (#not-kind-eq? @first "num_lit") + (#not-kind-eq? @first "kwd_lit") + (#not-match? @first "^(def|defn|defn-|defmacro|defmethod|defmulti|defonce|defprotocol|deftype|defrecord|defstruct|definline|definterface|deftest|ns|let|letfn|binding|loop|for|doseq|dotimes|when-let|if-let|when-some|if-some|with-.*|fn)$")) @indent + +(list_lit . (_) @first . (_) @second + (#not-same-line? @first @second) + (#not-kind-eq? @first "bool_lit") + (#not-kind-eq? @first "nil_lit") + (#not-kind-eq? @first "str_lit") + (#not-kind-eq? @first "num_lit") + (#not-kind-eq? @first "kwd_lit") + (#not-match? @first "^(def|defn|defn-|defmacro|defmethod|defmulti|defonce|defprotocol|deftype|defrecord|defstruct|definline|definterface|deftest|ns|let|letfn|binding|loop|for|doseq|dotimes|when-let|if-let|when-some|if-some|with-.*|fn)$")) @indent + +; If the first element is a literal, align the list to it +(list_lit . [(bool_lit) (nil_lit) (str_lit) (num_lit) (kwd_lit)] @anchor + ) @align + +; Special indentation for def-like forms, let bindings, and other special forms +; These forms typically have the body indented by one level after the name/bindings +(list_lit . (sym_lit) @first + (#match? @first "^(def|defn|defn-|defmacro|defmethod|defmulti|defonce|defprotocol|deftype|defrecord|defstruct|definline|definterface|deftest|ns|let|letfn|binding|loop|for|doseq|dotimes|when-let|if-let|when-some|if-some|with-.*|fn)$")) @indent + +; Align vector/map elements when first two are on same line (e.g., let bindings) +(vec_lit . (_) @anchor . (_) @second + (#same-line? @anchor @second) + ) @align + +(map_lit . (_) @anchor . (_) @second + (#same-line? @anchor @second) + ) @align + +; Indent vectors, maps, and sets +[(vec_lit) (map_lit) (set_lit)] @indent diff --git a/vendor/queries/cpp/indents.scm b/vendor/queries/cpp/indents.scm new file mode 100644 index 00000000..ea91ba4b --- /dev/null +++ b/vendor/queries/cpp/indents.scm @@ -0,0 +1,63 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/cpp/indents.scm, with what it inherits from c inlined. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (compound_statement) + (declaration_list) + (field_declaration_list) + (enumerator_list) + (parameter_list) + (init_declarator) + (expression_statement) +] @indent + +[ + "case" + "default" + "}" + "]" + ")" +] @outdent + +; Single statement after if/while/for/do without braces. Capture the body child +; naturally; on a typed newline the engine descends into it (no wrapper trick). +(if_statement + consequence: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(while_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(do_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) +(for_statement + body: (_) @indent + (#not-kind-eq? @indent "compound_statement") + (#set! "scope" "header")) + +(parameter_list + . (parameter_declaration) @anchor + ) @align +(argument_list + . (_) @anchor + ) @align +; These are a bit opinionated since some people just indent binary/ternary expressions spanning multiple lines. +; Since they are only triggered when a newline is inserted into an already complete binary/ternary expression, +; this should happen rarely, so it is not a big deal either way. +; Additionally, adding these queries has the advantage of preventing such continuation lines from being used +; as the baseline when the `hybrid` indent heuristic is used (which is desirable since their indentation is so inconsistent). +(binary_expression + ) @anchor @align +(conditional_expression + "?" @anchor + ) @align + + +(access_specifier) @outdent + +(raw_string_literal) @opaque diff --git a/vendor/queries/css/indents.scm b/vendor/queries/css/indents.scm new file mode 100644 index 00000000..e42c3be0 --- /dev/null +++ b/vendor/queries/css/indents.scm @@ -0,0 +1,12 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/css/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (block) +] @indent + +[ + "}" +] @outdent diff --git a/vendor/queries/elixir/indents.scm b/vendor/queries/elixir/indents.scm new file mode 100644 index 00000000..cc535930 --- /dev/null +++ b/vendor/queries/elixir/indents.scm @@ -0,0 +1,27 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/elixir/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (anonymous_function) + (do_block) + (stab_clause) + (map) + (list) + (tuple) +] @indent + +; The else/rescue/catch/after clause blocks nest *inside* the do_block, which +; already provides the body's one level of indent; the keyword itself outdents +; back to the construct's level. +[ + "end" + "else" + "rescue" + "catch" + "after" + "]" + "}" + ")" +] @outdent diff --git a/vendor/queries/fortran/indents.scm b/vendor/queries/fortran/indents.scm new file mode 100644 index 00000000..073d4f32 --- /dev/null +++ b/vendor/queries/fortran/indents.scm @@ -0,0 +1,36 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/fortran/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (module) + (submodule) + (program) + (subroutine) + (module_procedure) + (function) + ; (interface) + (if_statement) + (do_loop) + (where_statement) + (derived_type_definition) + (enum) +] @indent + +[ + (end_module_statement) + (end_submodule_statement) + (end_program_statement) + (end_subroutine_statement) + (end_module_procedure_statement) + (end_function_statement) + ; (end_interface_statement) + (end_if_statement) + (end_do_loop_statement) + (else_clause) + (elseif_clause) + (end_type_statement) + (end_enum_statement) + (end_where_statement) +] @outdent diff --git a/vendor/queries/go/indents.scm b/vendor/queries/go/indents.scm new file mode 100644 index 00000000..3734f458 --- /dev/null +++ b/vendor/queries/go/indents.scm @@ -0,0 +1,55 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/go/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +[ + (import_declaration) + (const_declaration) + (type_declaration) + (type_spec) + (func_literal) + (literal_value) + (literal_element) + (keyed_element) + (expression_case) + (default_case) + (type_case) + (communication_case) + (argument_list) + (parameter_list) + (field_declaration_list) + (block) + (var_declaration) + (selector_expression) + (binary_expression) +] @indent + +[ + "]" + ")" +] @outdent + +; Switches and selects aren't indented, only their case bodies are. +; Outdent all closing braces except those closing switches or selects. +( + (_ "}" @outdent) @outer + (#not-kind-eq? @outer "select_statement") + (#not-kind-eq? @outer "type_switch_statement") + (#not-kind-eq? @outer "expression_switch_statement") +) + +; Handle ERROR nodes for when auto-pairs is disabled. +; Typing an opening delimiter without a closing one produces an ERROR node. +(ERROR "{") @indent @extend +(ERROR "(") @indent +(ERROR "[") @indent + +; Labels (`Loop:`, `done:`) are de-indented one level by gofmt. +; Capturing the label_name (a child, not an ancestor of the labeled body) +; outdents only the label line. +(labeled_statement + (label_name) @outdent) + +; Raw string literals (backticks) span lines and are literal content. +(raw_string_literal) @opaque diff --git a/vendor/queries/html/indents.scm b/vendor/queries/html/indents.scm new file mode 100644 index 00000000..ea83fddd --- /dev/null +++ b/vendor/queries/html/indents.scm @@ -0,0 +1,20 @@ +; Vendored from helix (https://github.com/helix-editor/helix) at 278b24389: +; runtime/queries/html/indents.scm. +; Licensed under the Mozilla Public License 2.0 (vendor/queries/helix.LICENSE, +; https://mozilla.org/MPL/2.0/). + +; Indent the contents of an element; pull the end tag — and the close of a +; multi-line start/self-closing tag — back to the element's column. Mirrors the +; jsx rules. Void elements (`
`, ``) are single-line `element`s, so the +; tail-scoped indent is a no-op for them. +[ + (element) + (script_element) + (style_element) +] @indent +(end_tag) @outdent +(start_tag ">" @outdent) +(self_closing_tag "/>" @outdent) + +;