From: Juri Linkov Date: Sat, 15 Mar 2025 18:37:46 +0000 (+0200) Subject: Add the treesit 'list' thing to csharp/go/php/rust-ts-mode (bug#73404) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=57e505d12737422aa505e6c875ecaef099c4b6d2;p=emacs.git Add the treesit 'list' thing to csharp/go/php/rust-ts-mode (bug#73404) * lisp/progmodes/csharp-mode.el (csharp-ts-mode): Add the 'list' and 'sentence' things to 'treesit-thing-settings'. Set 'treesit-outline-predicate'. * lisp/progmodes/go-ts-mode.el (go-ts-mode): Add 'treesit-thing-settings' with the 'list' and 'sentence' things. * lisp/progmodes/php-ts-mode.el (php-ts-mode): Add the 'list' thing to 'treesit-thing-settings'. * lisp/progmodes/rust-ts-mode.el (rust-ts-mode): Add 'treesit-thing-settings' with the 'list' thing. (cherry picked from commit f3925732bc55be3d6d32d20b95f7a88926d4ebda) --- diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index 6f3fd08089f..5e9b8d680eb 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el @@ -1067,6 +1067,68 @@ Key bindings: (setq-local treesit-thing-settings `((c-sharp + (list + ,(rx bos (or "global_attribute" + "attribute_argument_list" + "attribute_list" + "enum_member_declaration_list" + "type_parameter_list" + "declaration_list" + "accessor_list" + "bracketed_parameter_list" + "parameter_list" + "argument_list" + "tuple_pattern" + "block" + "bracketed_argument_list" + "type_argument_list" + "array_rank_specifier" + "function_pointer_type" + "tuple_type" + "_for_statement_conditions" + "switch_body" + "catch_declaration" + "catch_filter_clause" + "parenthesized_pattern" + "list_pattern" + "positional_pattern_clause" + "property_pattern_clause" + "parenthesized_variable_designation" + "_switch_expression_body" + "interpolated_string_expression" + "interpolation" + "parenthesized_expression" + "_parenthesized_lvalue_expression" + "anonymous_object_creation_expression" + "initializer_expression" + "_with_body" + "tuple_expression" + "preproc_parenthesized_expression") + eos)) + (sentence + ,(rx bos (or "extern_alias_directive" + "using_directive" + "file_scoped_namespace_declaration" + "enum_declaration" + "delegate_declaration" + "_declaration_list_body" + "field_declaration" + "event_declaration" + "event_field_declaration" + "indexer_declaration" + "property_declaration" + "_function_body" + "break_statement" + "continue_statement" + "do_statement" + "empty_statement" + "expression_statement" + "return_statement" + "yield_statement" + "throw_statement" + "goto_statement" + "local_declaration_statement") + eos)) (text ,(regexp-opt '("comment" "verbatim_string-literal" @@ -1100,6 +1162,18 @@ Key bindings: ("Struct" "\\`struct_declaration\\'" nil nil) ("Method" "\\`method_declaration\\'" nil nil))) + ;; Outline minor mode. + (setq-local treesit-outline-predicate + (rx bos (or "namespace_declaration" + "class_declaration" + "interface_declaration" + "enum_declaration" + "record_declaration" + "struct_declaration" + "method_declaration" + "local_function_statement") + eos)) + (treesit-major-mode-setup) (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-ts-mode))) diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 86d98d90d3e..6d59f6ed494 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -290,6 +290,25 @@ "type_declaration"))) (setq-local treesit-defun-name-function #'go-ts-mode--defun-name) + (setq-local treesit-thing-settings + `((go + (list + ,(rx bos (or "import_spec_list" + "var_spec_list" + "type_parameter_list" + "parameter_list" + "parenthesized_type" + "type_arguments" + "field_declaration_list" + "block" + "parenthesized_expression" + "special_argument_list" + "argument_list" + "literal_value") + eos)) + (sentence + (or "declaration" "statement"))))) + ;; Imenu. (setq-local treesit-simple-imenu-settings `(("Function" "\\`function_declaration\\'" nil nil) diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index 435def99645..b2e953ba5e8 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el @@ -1470,6 +1470,22 @@ Depends on `c-ts-common-comment-setup'." `((php (defun ,treesit-defun-type-regexp) (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ",")))) + (list + ,(rx bos (or "namespace_use_group" + "enum_declaration_list" + "declaration_list" + "property_hook_list" + "use_list" + "anonymous_function_use_clause" + "formal_parameters" + "match_block" + "switch_block" + "compound_statement" + "parenthesized_expression" + "_array_destructing" + "arguments" + "_complex_string_part") + eos)) (sentence ,(regexp-opt '("break_statement" "case_statement" diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index 0fe5fcc083b..ae2bc8ee78c 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el @@ -597,6 +597,40 @@ See `prettify-symbols-compose-predicate'." "struct_item"))) (setq-local treesit-defun-name-function #'rust-ts-mode--defun-name) + (setq-local treesit-thing-settings + `((rust + (list + ,(rx bos (or "token_tree_pattern" + "token_tree" + "attribute_item" + "inner_attribute_item" + "declaration_list" + "enum_variant_list" + "field_declaration_list" + "ordered_field_declaration_list" + "type_parameters" + "use_list" + "parameters" + "bracketed_type" + "array_type" + "for_lifetimes" + "tuple_type" + "unit_type" + "use_bounds" + "type_arguments" + "delim_token_tree" + "arguments" + "array_expression" + "parenthesized_expression" + "tuple_expression" + "unit_expression" + "field_initializer_list" + "match_block" + "block" + "tuple_pattern" + "slice_pattern") + eos))))) + (treesit-major-mode-setup))) (derived-mode-add-parents 'rust-ts-mode '(rust-mode))