branch: elpa/treesit-fold
commit bb5bd2e31e5a576bf254eb58b6f7143f041a3b79
Author: Jen-Chieh Shen <[email protected]>
Commit: GitHub <[email protected]>
feat: Add Clojure support (#64)
---
README.md | 2 +-
ts-fold-parsers.el | 10 ++++++++++
ts-fold-summary.el | 1 +
ts-fold.el | 12 ++++++++++++
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 698a8e6a3c..403087c0c1 100644
--- a/README.md
+++ b/README.md
@@ -113,7 +113,7 @@ If evil mode is loaded, then these commands are also added
to the evil folding l
These languages are fairly complete:
- Bash
-- C / C++ / C# / CSS
+- C / C++ / C# / Clojure / CSS
- Dart
- Elisp / Elixir
- Go
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index f98c77a27b..02c4cbb5cc 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -54,6 +54,7 @@
(declare-function ts-fold-range-lua-do-loop "ts-fold.el")
(declare-function ts-fold-range-lua-repeat "ts-fold.el")
(declare-function ts-fold-range-ocaml "ts-fold.el")
+(declare-function ts-fold-range-clojure-function "ts-fold.el")
(declare-function ts-fold-range-python-def "ts-fold.el")
(declare-function ts-fold-range-python-expression-statement "ts-fold.el")
(declare-function ts-fold-range-ruby-class-def "ts-fold.el")
@@ -96,6 +97,15 @@
"Rule set for C++."
(append (ts-fold-parsers-c)))
+(defun ts-fold-parsers-clojure ()
+ "Rule set for Clojure."
+ '((list_lit . ts-fold-range-clojure-function)
+ (map_lit . ts-fold-range-seq)
+ (str_lit . ts-fold-range-seq)
+ (comment
+ . (lambda (node offset)
+ (ts-fold-range-line-comment node offset ";;")))))
+
(defun ts-fold-parsers-csharp ()
"Rule set for C#."
'((block . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 4bf0532380..a3360741fe 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -207,6 +207,7 @@ type of content by checking the word boundary's existence."
(bat-mode . ts-fold-summary-batch)
(c-mode . ts-fold-summary-c)
(c++-mode . ts-fold-summary-c)
+ (clojure-mode . ts-fold-summary-elisp)
(csharp-mode . ts-fold-summary-csharp)
(css-mode . ts-fold-summary-javadoc)
(dart-mode . ts-fold-summary-javadoc)
diff --git a/ts-fold.el b/ts-fold.el
index 77b8d48aa0..dd8cba6d2a 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -63,6 +63,7 @@
(c-mode . ,(ts-fold-parsers-c))
(c++-mode . ,(ts-fold-parsers-c++))
(caml-mode . ,(ts-fold-parsers-ocaml))
+ (clojure-mode . ,(ts-fold-parsers-clojure))
(csharp-mode . ,(ts-fold-parsers-csharp))
(css-mode . ,(ts-fold-parsers-css))
(dart-mode . ,(ts-fold-parsers-dart))
@@ -604,6 +605,17 @@ more information."
;;- OCaml
+(defun ts-fold-range-clojure-function (node offset)
+ "Return the fold range for `list_lit' NODE in Clojure.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((param-node (car (ts-fold-find-children node "vec_lit")))
+ (next-node (tsc-get-next-sibling param-node))
+ (beg (tsc-node-start-position next-node))
+ (end (1- (tsc-node-end-position node))))
+ (ts-fold--cons-add (cons beg end) offset)))
+
(defun ts-fold-range-python-def (node offset)
"Define fold range for `function_definition' and `class_definition'.