* 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'.
This commit is contained in:
Juri Linkov 2025-02-07 09:47:41 +02:00
parent 1751739152
commit f6e6585f57

View 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))