From f6e6585f5751852dbdc972fef8fc5a3ccc6e4573 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Fri, 7 Feb 2025 09:47:41 +0200 Subject: [PATCH] * lisp/progmodes/sh-script.el (bash-ts-mode): Improve treesit settings. Add 'list' and 'sentence' things to treesit-thing-settings, and move mistakenly added 'sentence' to 'text' (bug#73404). Set 'treesit-defun-name-function' and 'treesit-simple-imenu-settings'. Reset 'outline-regexp'. --- lisp/progmodes/sh-script.el | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 3a41ef297ef..c4b7d0837a4 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -1646,10 +1646,45 @@ not written in Bash or sh." sh-mode--treesit-settings) (setq-local treesit-thing-settings `((bash - (sentence ,(regexp-opt '("comment" - "heredoc_start" - "heredoc_body")))))) + (list + ,(rx bos (or "do_group" + "if_statement" + "case_statement" + "compound_statement" + "subshell" + "test_command" + "parenthesized_expression" + "arithmetic_expansion" + "brace_expression" + "string" + "array" + "expansion" ;; but not "simple_expansion" + "command_substitution" + "process_substitution") + eos)) + (sentence + ,(rx bos (or "redirected_statement" + "declaration_command" + "unset_command" + "command" + "variable_assignment") + eos)) + (text + ,(rx bos (or "comment" + "heredoc_body") + eos))))) (setq-local treesit-defun-type-regexp "function_definition") + (setq-local treesit-defun-name-function + (lambda (node) + (treesit-node-text + (treesit-node-child-by-field-name node "name") + t))) + (setq-local treesit-simple-imenu-settings + '((nil "\\`function_definition\\'" nil nil))) + ;; Override regexp-based outline variable from `sh-base-mode' + ;; to use `treesit-simple-imenu-settings' for outlines: + (kill-local-variable 'outline-regexp) + (treesit-major-mode-setup))) (derived-mode-add-parents 'bash-ts-mode '(sh-mode))