emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/treesit-fold ae12dd8717 217/417: Support elixir (#10)


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold ae12dd8717 217/417: Support elixir (#10)
Date: Mon, 1 Jul 2024 10:02:27 -0400 (EDT)

branch: elpa/treesit-fold
commit ae12dd8717730e6908c3e930a5e2889767be1426
Author: mohammedzeglam-pg <56762707+mohammedzeglam-pg@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Support elixir (#10)
    
    * Support elixir
    
    * Add Elixir to supported languages in README
    
    * aliast in alphabetic order
---
 README.md          |  2 +-
 ts-fold-parsers.el | 11 ++++++++++-
 ts-fold.el         | 14 +++++++++++++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 40121cf535..cecbd84862 100644
--- a/README.md
+++ b/README.md
@@ -81,12 +81,12 @@ then in Emacs:
 * R / Ruby / Rust
 * Scala / Swift
 * TypeScript / TSX
+* Elixir
 
 > These languages are in development:
 
 * Agda
 * Elm
-* Elixir
 * Emacs Lisp
 * XML (upstream)
 
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 956391ea3d..0139f447aa 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -48,6 +48,7 @@
 (declare-function ts-fold-range-python "ts-fold.el")
 (declare-function ts-fold-range-ruby "ts-fold.el")
 (declare-function ts-fold-range-rust-macro "ts-fold.el")
+(declare-function ts-fold-range-elixir "ts-fold.el")
 
 ;;
 ;; (@* "Parsers" )
@@ -217,6 +218,14 @@
 (defun ts-fold-parsers-typescript ()
   "Rule sets for TypeScript."
   (append (ts-fold-parsers-javascript)))
-
+(defun ts-fold-parsers-elixir ()
+  "Rules sets for Elixir."
+  '((list . ts-fold-range-seq)
+    (map . ts-fold-range-seq)
+    (tuple . ts-fold-range-seq)
+    (comment
+     . (lambda (node offset)
+         (ts-fold-range-line-comment node offset "#")))
+    (do_block .ts-fold-range-elixir)))
 (provide 'ts-fold-parsers)
 ;;; ts-fold-parsers.el ends here
diff --git a/ts-fold.el b/ts-fold.el
index 2a0d5aa668..5ea0393d8d 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -65,7 +65,7 @@ The alist is in form of (major-mode . (foldable-node-type)).")
 ;; alphabetically sorted
 (defcustom ts-fold-range-alist
   `((agda-mode       . ,(ts-fold-parsers-agda))
-    (sh-mode         . ,(ts-fold-parsers-bash))
+    (elixir-mode     . ,(ts-fold-parsers-elixir))
     (c-mode          . ,(ts-fold-parsers-c))
     (c++-mode        . ,(ts-fold-parsers-c++))
     (csharp-mode     . ,(ts-fold-parsers-csharp))
@@ -87,6 +87,7 @@ The alist is in form of (major-mode . (foldable-node-type)).")
     (ruby-mode       . ,(ts-fold-parsers-ruby))
     (rust-mode       . ,(ts-fold-parsers-rust))
     (rustic-mode     . ,(ts-fold-parsers-rust))
+    (sh-mode         . ,(ts-fold-parsers-bash))
     (scala-mode      . ,(ts-fold-parsers-scala))
     (swift-mode      . ,(ts-fold-parsers-swift))
     (typescript-mode . ,(ts-fold-parsers-typescript)))
@@ -483,5 +484,16 @@ more information."
               (end (1+ (tsc-node-start-position last_bracket))))
     (ts-fold--cons-add (cons beg end) offset)))
 
+(defun ts-fold-range-elixir (node offset)
+  "Return the fold range for `function' `module' NODE in Elixir.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let* ((children (tsc-count-children node))
+              (end_child (tsc-get-nth-child node (- children 1)))
+              (do_child (tsc-get-nth-child node 1))
+              (beg (tsc-node-start-position do_child))
+              (end (tsc-node-start-position end_child)))
+    (ts-fold--cons-add (cons beg end) offset)))
 (provide 'ts-fold)
 ;;; ts-fold.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]