1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-26 07:00:35 -08:00

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.
This commit is contained in:
Yuan Fu 2025-01-30 16:54:20 -08:00
parent a5965217fc
commit ef28af35bb
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
3 changed files with 54 additions and 0 deletions

View file

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