1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Use TS to support 'hs-minor-mode' in 'lua-ts-mode'

* lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Add list type to
'treesit-thing-settings'.
* lisp/progmodes/hideshow.el (hs-special-modes-alist):
Remove regular expression based implementation.
* test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua: New file.
* test/lisp/progmodes/lua-ts-mode-tests.el (lua-ts-test-hideshow):
Add test.  (Bug#76693)
This commit is contained in:
john muhl 2025-02-26 10:31:24 -06:00 committed by Juri Linkov
parent 7905ea761a
commit 2f1b1414f7
4 changed files with 83 additions and 20 deletions

View file

@ -266,7 +266,6 @@ This has effect only if `search-invisible' is set to `open'."
(java-ts-mode "{" "}" "/[*/]" nil nil)
(js-mode "{" "}" "/[*/]" nil)
(js-ts-mode "{" "}" "/[*/]" nil)
(lua-ts-mode "{\\|\\[\\[" "}\\|\\]\\]" "--" nil)
(mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil)
;; Add more support here.
)

View file

@ -791,31 +791,39 @@ Calls REPORT-FN directly."
(rx (or "function_declaration" "function_definition")))
(setq-local treesit-thing-settings
`((lua
(function ,(rx (or "function_declaration"
"function_definition")))
(function (or "function_declaration"
"function_definition"))
(keyword ,(regexp-opt lua-ts--keywords 'symbols))
(loop-statement ,(rx (or "do_statement"
"for_statement"
"repeat_statement"
"while_statement")))
(loop-statement (or "do_statement"
"for_statement"
"repeat_statement"
"while_statement"))
(sentence (or function
loop-statement
,(rx (or "assignment_statement"
"comment"
"field"
"function_call"
"if_statement"
"return_statement"
"variable_declaration"))))
comment
"assignment_statement"
"field"
"function_call"
"if_statement"
"return_statement"
"variable_declaration"))
(sexp (or function
keyword
loop-statement
,(rx (or "arguments"
"parameters"
"parenthesized_expression"
"string"
"table_constructor"))))
(text "comment"))))
"arguments"
"parameters"
"parenthesized_expression"
"string"
"table_constructor"))
(list (or function
loop-statement
"arguments"
"parameters"
"table_constructor"
"parenthesized_expression"
,(rx bos "if_statement" eos)))
(text (or comment "string"))
(comment ,(rx bos "comment" eos)))))
;; Imenu/Outline/Which-function.
(setq-local treesit-simple-imenu-settings

View file

@ -0,0 +1,43 @@
--[[
This is a
comment block.
]]
local function fun ()
print("fun")
end
local f = (function ()
print(1)
end)
for i = 1, 10 do
print(i)
end
repeat
print("repeat")
until false
while true do
print("while")
end
do
print(1)
end
local t = {
a=1,
b=2,
}
if true then
print(1)
elseif false then
print(0)
else
print(0)
end
function f1 (has,
lots,
of,
parameters)
print("ok")
end
print(1,
2,
3,
4)

View file

@ -22,6 +22,7 @@
(require 'ert)
(require 'ert-font-lock)
(require 'ert-x)
(require 'hideshow)
(require 'treesit)
(require 'which-func)
@ -48,6 +49,18 @@
(should (equal "f" (which-function)))
(which-function-mode -1)))
(ert-deftest lua-ts-test-hideshow ()
(skip-unless (treesit-ready-p 'lua t))
(with-temp-buffer
(insert-file-contents (ert-resource-file "hide-show.lua"))
(lua-ts-mode)
(hs-minor-mode)
(hs-hide-all)
(should (= 11 (length (overlays-in (point-min) (point-max)))))
(hs-show-all)
(should (= 0 (length (overlays-in (point-min) (point-max)))))
(hs-minor-mode -1)))
(provide 'lua-ts-mode-tests)
;;; lua-ts-mode-tests.el ends here