diff options
| author | john muhl | 2025-02-26 10:31:24 -0600 |
|---|---|---|
| committer | Juri Linkov | 2025-03-08 20:50:59 +0200 |
| commit | 2f1b1414f78e471f1c4e852c1cbd8320cb0fa60d (patch) | |
| tree | d8b836cb8f2ae5a4460d9a2d4697417c5e1fc55e | |
| parent | 7905ea761ac8405628993708b4c1d4516370067c (diff) | |
| download | emacs-2f1b1414f78e471f1c4e852c1cbd8320cb0fa60d.tar.gz emacs-2f1b1414f78e471f1c4e852c1cbd8320cb0fa60d.zip | |
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)
| -rw-r--r-- | lisp/progmodes/hideshow.el | 1 | ||||
| -rw-r--r-- | lisp/progmodes/lua-ts-mode.el | 46 | ||||
| -rw-r--r-- | test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua | 43 | ||||
| -rw-r--r-- | test/lisp/progmodes/lua-ts-mode-tests.el | 13 |
4 files changed, 83 insertions, 20 deletions
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index c9b43fe8e16..c1d62fb92ab 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el | |||
| @@ -266,7 +266,6 @@ This has effect only if `search-invisible' is set to `open'." | |||
| 266 | (java-ts-mode "{" "}" "/[*/]" nil nil) | 266 | (java-ts-mode "{" "}" "/[*/]" nil nil) |
| 267 | (js-mode "{" "}" "/[*/]" nil) | 267 | (js-mode "{" "}" "/[*/]" nil) |
| 268 | (js-ts-mode "{" "}" "/[*/]" nil) | 268 | (js-ts-mode "{" "}" "/[*/]" nil) |
| 269 | (lua-ts-mode "{\\|\\[\\[" "}\\|\\]\\]" "--" nil) | ||
| 270 | (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil) | 269 | (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil) |
| 271 | ;; Add more support here. | 270 | ;; Add more support here. |
| 272 | ) | 271 | ) |
diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index de93d0fdaba..b4025c23649 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el | |||
| @@ -791,31 +791,39 @@ Calls REPORT-FN directly." | |||
| 791 | (rx (or "function_declaration" "function_definition"))) | 791 | (rx (or "function_declaration" "function_definition"))) |
| 792 | (setq-local treesit-thing-settings | 792 | (setq-local treesit-thing-settings |
| 793 | `((lua | 793 | `((lua |
| 794 | (function ,(rx (or "function_declaration" | 794 | (function (or "function_declaration" |
| 795 | "function_definition"))) | 795 | "function_definition")) |
| 796 | (keyword ,(regexp-opt lua-ts--keywords 'symbols)) | 796 | (keyword ,(regexp-opt lua-ts--keywords 'symbols)) |
| 797 | (loop-statement ,(rx (or "do_statement" | 797 | (loop-statement (or "do_statement" |
| 798 | "for_statement" | 798 | "for_statement" |
| 799 | "repeat_statement" | 799 | "repeat_statement" |
| 800 | "while_statement"))) | 800 | "while_statement")) |
| 801 | (sentence (or function | 801 | (sentence (or function |
| 802 | loop-statement | 802 | loop-statement |
| 803 | ,(rx (or "assignment_statement" | 803 | comment |
| 804 | "comment" | 804 | "assignment_statement" |
| 805 | "field" | 805 | "field" |
| 806 | "function_call" | 806 | "function_call" |
| 807 | "if_statement" | 807 | "if_statement" |
| 808 | "return_statement" | 808 | "return_statement" |
| 809 | "variable_declaration")))) | 809 | "variable_declaration")) |
| 810 | (sexp (or function | 810 | (sexp (or function |
| 811 | keyword | 811 | keyword |
| 812 | loop-statement | 812 | loop-statement |
| 813 | ,(rx (or "arguments" | 813 | "arguments" |
| 814 | "parameters" | 814 | "parameters" |
| 815 | "parenthesized_expression" | 815 | "parenthesized_expression" |
| 816 | "string" | 816 | "string" |
| 817 | "table_constructor")))) | 817 | "table_constructor")) |
| 818 | (text "comment")))) | 818 | (list (or function |
| 819 | loop-statement | ||
| 820 | "arguments" | ||
| 821 | "parameters" | ||
| 822 | "table_constructor" | ||
| 823 | "parenthesized_expression" | ||
| 824 | ,(rx bos "if_statement" eos))) | ||
| 825 | (text (or comment "string")) | ||
| 826 | (comment ,(rx bos "comment" eos))))) | ||
| 819 | 827 | ||
| 820 | ;; Imenu/Outline/Which-function. | 828 | ;; Imenu/Outline/Which-function. |
| 821 | (setq-local treesit-simple-imenu-settings | 829 | (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 index 00000000000..a4831eba273 --- /dev/null +++ b/test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | --[[ | ||
| 2 | This is a | ||
| 3 | comment block. | ||
| 4 | ]] | ||
| 5 | local function fun () | ||
| 6 | print("fun") | ||
| 7 | end | ||
| 8 | local f = (function () | ||
| 9 | print(1) | ||
| 10 | end) | ||
| 11 | for i = 1, 10 do | ||
| 12 | print(i) | ||
| 13 | end | ||
| 14 | repeat | ||
| 15 | print("repeat") | ||
| 16 | until false | ||
| 17 | while true do | ||
| 18 | print("while") | ||
| 19 | end | ||
| 20 | do | ||
| 21 | print(1) | ||
| 22 | end | ||
| 23 | local t = { | ||
| 24 | a=1, | ||
| 25 | b=2, | ||
| 26 | } | ||
| 27 | if true then | ||
| 28 | print(1) | ||
| 29 | elseif false then | ||
| 30 | print(0) | ||
| 31 | else | ||
| 32 | print(0) | ||
| 33 | end | ||
| 34 | function f1 (has, | ||
| 35 | lots, | ||
| 36 | of, | ||
| 37 | parameters) | ||
| 38 | print("ok") | ||
| 39 | end | ||
| 40 | print(1, | ||
| 41 | 2, | ||
| 42 | 3, | ||
| 43 | 4) | ||
diff --git a/test/lisp/progmodes/lua-ts-mode-tests.el b/test/lisp/progmodes/lua-ts-mode-tests.el index 44c31648586..b14e9518451 100644 --- a/test/lisp/progmodes/lua-ts-mode-tests.el +++ b/test/lisp/progmodes/lua-ts-mode-tests.el | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'ert-font-lock) | 23 | (require 'ert-font-lock) |
| 24 | (require 'ert-x) | 24 | (require 'ert-x) |
| 25 | (require 'hideshow) | ||
| 25 | (require 'treesit) | 26 | (require 'treesit) |
| 26 | (require 'which-func) | 27 | (require 'which-func) |
| 27 | 28 | ||
| @@ -48,6 +49,18 @@ | |||
| 48 | (should (equal "f" (which-function))) | 49 | (should (equal "f" (which-function))) |
| 49 | (which-function-mode -1))) | 50 | (which-function-mode -1))) |
| 50 | 51 | ||
| 52 | (ert-deftest lua-ts-test-hideshow () | ||
| 53 | (skip-unless (treesit-ready-p 'lua t)) | ||
| 54 | (with-temp-buffer | ||
| 55 | (insert-file-contents (ert-resource-file "hide-show.lua")) | ||
| 56 | (lua-ts-mode) | ||
| 57 | (hs-minor-mode) | ||
| 58 | (hs-hide-all) | ||
| 59 | (should (= 11 (length (overlays-in (point-min) (point-max))))) | ||
| 60 | (hs-show-all) | ||
| 61 | (should (= 0 (length (overlays-in (point-min) (point-max))))) | ||
| 62 | (hs-minor-mode -1))) | ||
| 63 | |||
| 51 | (provide 'lua-ts-mode-tests) | 64 | (provide 'lua-ts-mode-tests) |
| 52 | 65 | ||
| 53 | ;;; lua-ts-mode-tests.el ends here | 66 | ;;; lua-ts-mode-tests.el ends here |