]> git.eshelyaron.com Git - emacs.git/commitdiff
Use TS to support 'hs-minor-mode' in 'lua-ts-mode'
authorjohn muhl <jm@pub.pink>
Wed, 26 Feb 2025 16:31:24 +0000 (10:31 -0600)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Mar 2025 10:30:35 +0000 (11:30 +0100)
* 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)

(cherry picked from commit 2f1b1414f78e471f1c4e852c1cbd8320cb0fa60d)

lisp/progmodes/hideshow.el
lisp/progmodes/lua-ts-mode.el
test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua [new file with mode: 0644]
test/lisp/progmodes/lua-ts-mode-tests.el

index c9b43fe8e16acbb7198a0c1c0ab9ce5a8d34acda..c1d62fb92ab76eb6ad23004ee1b9dfb0f6367a1c 100644 (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.
     )
index de93d0fdaba11ed1f727f0a9d39e1a0e6f53711e..b4025c236491b2eb2e78dacdbc31a3e1b44671b5 100644 (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
diff --git a/test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua b/test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua
new file mode 100644 (file)
index 0000000..a4831eb
--- /dev/null
@@ -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)
index 44c316485860c5cc7322c490db0ac0c600e3c6be..b14e951845176de9807d2602944a3de8fe62fc0a 100644 (file)
@@ -22,6 +22,7 @@
 (require 'ert)
 (require 'ert-font-lock)
 (require 'ert-x)
+(require 'hideshow)
 (require 'treesit)
 (require 'which-func)
 
     (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