Skip to content

Commit ae12dd8

Browse files
Support elixir (#10)
* Support elixir * Add Elixir to supported languages in README * aliast in alphabetic order
1 parent afa4f3b commit ae12dd8

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ then in Emacs:
8181
* R / Ruby / Rust
8282
* Scala / Swift
8383
* TypeScript / TSX
84+
* Elixir
8485

8586
> These languages are in development:
8687
8788
* Agda
8889
* Elm
89-
* Elixir
9090
* Emacs Lisp
9191
* XML (upstream)
9292

ts-fold-parsers.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
(declare-function ts-fold-range-python "ts-fold.el")
4949
(declare-function ts-fold-range-ruby "ts-fold.el")
5050
(declare-function ts-fold-range-rust-macro "ts-fold.el")
51+
(declare-function ts-fold-range-elixir "ts-fold.el")
5152

5253
;;
5354
;; (@* "Parsers" )
@@ -217,6 +218,14 @@
217218
(defun ts-fold-parsers-typescript ()
218219
"Rule sets for TypeScript."
219220
(append (ts-fold-parsers-javascript)))
220-
221+
(defun ts-fold-parsers-elixir ()
222+
"Rules sets for Elixir."
223+
'((list . ts-fold-range-seq)
224+
(map . ts-fold-range-seq)
225+
(tuple . ts-fold-range-seq)
226+
(comment
227+
. (lambda (node offset)
228+
(ts-fold-range-line-comment node offset "#")))
229+
(do_block .ts-fold-range-elixir)))
221230
(provide 'ts-fold-parsers)
222231
;;; ts-fold-parsers.el ends here

ts-fold.el

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The alist is in form of (major-mode . (foldable-node-type)).")
6565
;; alphabetically sorted
6666
(defcustom ts-fold-range-alist
6767
`((agda-mode . ,(ts-fold-parsers-agda))
68-
(sh-mode . ,(ts-fold-parsers-bash))
68+
(elixir-mode . ,(ts-fold-parsers-elixir))
6969
(c-mode . ,(ts-fold-parsers-c))
7070
(c++-mode . ,(ts-fold-parsers-c++))
7171
(csharp-mode . ,(ts-fold-parsers-csharp))
@@ -87,6 +87,7 @@ The alist is in form of (major-mode . (foldable-node-type)).")
8787
(ruby-mode . ,(ts-fold-parsers-ruby))
8888
(rust-mode . ,(ts-fold-parsers-rust))
8989
(rustic-mode . ,(ts-fold-parsers-rust))
90+
(sh-mode . ,(ts-fold-parsers-bash))
9091
(scala-mode . ,(ts-fold-parsers-scala))
9192
(swift-mode . ,(ts-fold-parsers-swift))
9293
(typescript-mode . ,(ts-fold-parsers-typescript)))
@@ -483,5 +484,16 @@ more information."
483484
(end (1+ (tsc-node-start-position last_bracket))))
484485
(ts-fold--cons-add (cons beg end) offset)))
485486

487+
(defun ts-fold-range-elixir (node offset)
488+
"Return the fold range for `function' `module' NODE in Elixir.
489+
490+
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
491+
more information."
492+
(when-let* ((children (tsc-count-children node))
493+
(end_child (tsc-get-nth-child node (- children 1)))
494+
(do_child (tsc-get-nth-child node 1))
495+
(beg (tsc-node-start-position do_child))
496+
(end (tsc-node-start-position end_child)))
497+
(ts-fold--cons-add (cons beg end) offset)))
486498
(provide 'ts-fold)
487499
;;; ts-fold.el ends here

0 commit comments

Comments
 (0)