From ef28af35bb4c43d71fe4c10d02fe93f30e830c5e Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 30 Jan 2025 16:54:20 -0800 Subject: Add treesit-add-simple-indent-rules * lisp/treesit.el: (treesit-add-simple-indent-rules): New function. * etc/NEWS: Update NEWS. * test/src/treesit-tests.el: (treesit-test-add-simple-indent-rules): Add a test for the new function. --- test/src/treesit-tests.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/src') diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index f9c64f792d1..22f53243274 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el @@ -411,6 +411,27 @@ BODY is the test body." (let ((missing-bracket (treesit-node-child array -1))) (treesit-search-forward missing-bracket "" t)))) +;;; Indent + +(ert-deftest treesit-test-add-simple-indent-rules () + "Test `treesit-add-simple-indent-rules'." + (let ((treesit-simple-indent-rules + (copy-tree '((c (a a a) (b b b) (c c c)))))) + (treesit-add-simple-indent-rules 'c '((d d d))) + (should (equal treesit-simple-indent-rules + '((c (d d d) (a a a) (b b b) (c c c))))) + (treesit-add-simple-indent-rules 'c '((e e e)) :after) + (should (equal treesit-simple-indent-rules + '((c (d d d) (a a a) (b b b) (c c c) (e e e))))) + (treesit-add-simple-indent-rules 'c '((f f f)) :after '(b b b)) + (should (equal treesit-simple-indent-rules + '((c (d d d) (a a a) (b b b) (f f f) + (c c c) (e e e))))) + (treesit-add-simple-indent-rules 'c '((g g g)) :before '(b b b)) + (should (equal treesit-simple-indent-rules + '((c (d d d) (a a a) (g g g) + (b b b) (f f f) (c c c) (e e e))))))) + ;;; Query (defun treesit--ert-pred-last-sibling (node) -- cgit v1.2.1