Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Erlang support #83

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Add XML support (#80)
* Add Jsonnet support (#81)
* Add Zig support (#82)
* Add Erlang support (#83)

## 0.2.0
> Released Sep 01, 2023
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ These languages are fairly complete:
- Bash / Beancount
- C / C++ / C# / Clojure / CSS
- Dart
- Elisp / Elixir
- Elisp / Elixir / Erlang
- GDScript / Go
- Haskell / HTML
- Jai / Java / JavaScript / JSX / JSON / Jsonnet / Julia
Expand All @@ -137,7 +137,7 @@ These languages are in development:

- Ada
- Agda
- Elm / Erlang
- Elm

## 📝 Customization

Expand Down
11 changes: 11 additions & 0 deletions ts-fold-parsers.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
(declare-function ts-fold-range-c-preproc-else "ts-fold.el")
(declare-function ts-fold-range-elisp-function "ts-fold.el")
(declare-function ts-fold-range-elixir "ts-fold.el")
(declare-function ts-fold-range-erlang-clause-body "ts-fold.el")
(declare-function ts-fold-range-erlang-type-guards "ts-fold.el")
(declare-function ts-fold-range-haskell-function "ts-fold.el")
(declare-function ts-fold-range-html "ts-fold.el")
(declare-function ts-fold-range-julia "ts-fold.el")
Expand Down Expand Up @@ -171,6 +173,15 @@
. (lambda (node offset)
(ts-fold-range-line-comment node offset "#")))))

(defun ts-fold-parsers-erlang ()
"Rules set for Erlang."
'((list . ts-fold-range-seq)
(clause_body . ts-fold-range-erlang-clause-body)
(type_guards . ts-fold-range-erlang-type-guards)
(comment
. (lambda (node offset)
(ts-fold-range-line-comment node offset "%")))))

(defun ts-fold-parsers-gdscript ()
"Rule set for GGScript."
'((body . (ts-fold-range-seq -1 1))
Expand Down
1 change: 1 addition & 0 deletions ts-fold-summary.el
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type of content by checking the word boundary's existence."
(dart-mode . ts-fold-summary-javadoc)
(emacs-lisp-mode . ts-fold-summary-elisp)
(elixir-mode . ts-fold-summary-ruby-doc)
(erlang-mode . ts-fold-summary-tex-doc)
(gdscript-mode . ts-fold-summary-ruby-doc)
(go-mode . ts-fold-summary-go)
(haskell-mode . ts-fold-summary-lua-doc)
Expand Down
28 changes: 28 additions & 0 deletions ts-fold.el
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
(dart-mode . ,(ts-fold-parsers-dart))
(emacs-lisp-mode . ,(ts-fold-parsers-elisp))
(elixir-mode . ,(ts-fold-parsers-elixir))
(erlang-mode . ,(ts-fold-parsers-erlang))
(ess-r-mode . ,(ts-fold-parsers-r))
(gdscript-mode . ,(ts-fold-parsers-gdscript))
(go-mode . ,(ts-fold-parsers-go))
Expand Down Expand Up @@ -597,6 +598,33 @@ more information."
(setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))

(defun ts-fold-range-erlang-signature (node offset start)
"Return the fold range for generic signature NODE in Erlang.

For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information.

Argument START is a string to target for the first node we use to find the
start of the position."
(when-let* ((start-node (car (ts-fold-find-children node start)))
(beg (tsc-node-end-position start-node))
(end (tsc-node-end-position node)))
(ts-fold--cons-add (cons beg end) offset)))

(defun ts-fold-range-erlang-clause-body (node offset)
"Return the fold range for `clause_body' NODE in Erlang.

For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
(ts-fold-range-erlang-signature node offset "->"))

(defun ts-fold-range-erlang-type-guards (node offset)
"Return the fold range for `type_guards' NODE in Erlang.

For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
(ts-fold-range-erlang-signature node offset "when"))

(defun ts-fold-range-haskell-function (node offset)
"Define fold range for `function' in Haskell.

Expand Down
Loading