]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/sh-script.el (bash-ts-mode): Improve treesit settings.
authorJuri Linkov <juri@linkov.net>
Fri, 7 Feb 2025 07:47:41 +0000 (09:47 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Feb 2025 08:43:07 +0000 (09:43 +0100)
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'.

(cherry picked from commit f6e6585f5751852dbdc972fef8fc5a3ccc6e4573)

lisp/progmodes/sh-script.el

index ee84c7c613b020553f8978b450d2eda7c3c98e1d..2fb8c2608009524b9f1763f6589acb516cc71f19 100644 (file)
@@ -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))