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

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

[nongnu] elpa/treesit-fold 8734a2e2a8 288/417: feat: Add Beancount suppo


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 8734a2e2a8 288/417: feat: Add Beancount support (#74)
Date: Mon, 1 Jul 2024 10:02:36 -0400 (EDT)

branch: elpa/treesit-fold
commit 8734a2e2a8eaaf7bf024e2dcfd8ec8cfb5bd681f
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>

    feat: Add Beancount support (#74)
    
    * reorder lang
    
    * work on
---
 CHANGELOG.md       |   1 +
 README.md          |   2 +-
 ts-fold-parsers.el |   8 ++
 ts-fold-summary.el |   1 +
 ts-fold.el         | 305 +++++++++++++++++++++++++++--------------------------
 5 files changed, 169 insertions(+), 148 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f20ba52a65..4c6d7e46e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 * Add Jai support (#71)
 * Add GDScript support (#72)
 * Add Scheme support (#73)
+* Add Beancount support (#74)
 
 ## 0.1.0
 > Released Oct 18, 2021
diff --git a/README.md b/README.md
index a6bb3e5296..8def7c4855 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ If evil mode is loaded, then these commands are also added 
to the evil folding l
 
 These languages are fairly complete:
 
-- Bash
+- Bash / Beancount
 - C / C++ / C# / Clojure / CSS
 - Dart
 - Elisp / Elixir
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 040e9be1a9..9cdf533621 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -40,6 +40,7 @@
 (declare-function ts-fold-range-block-comment "ts-fold.el")
 (declare-function ts-fold-range-c-like-comment "ts-fold.el")
 
+(declare-function ts-fold-range-beancount-transaction "ts-fold.el")
 (declare-function ts-fold-range-c-preproc-ifdef "ts-fold.el")
 (declare-function ts-fold-range-c-preproc-if "ts-fold.el")
 (declare-function ts-fold-range-c-preproc-elif "ts-fold.el")
@@ -84,6 +85,13 @@
      . (lambda (node offset)
          (ts-fold-range-line-comment node offset "#")))))
 
+(defun ts-fold-parsers-beancount ()
+  "Rule set for Beancount."
+  '((transaction . ts-fold-range-beancount-transaction)
+    (comment
+     . (lambda (node offset)
+         (ts-fold-range-line-comment node offset ";;")))))
+
 (defun ts-fold-parsers-c ()
   "Rule set for C."
   '((compound_statement     . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index a9d1eeeab1..52a5731da1 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -205,6 +205,7 @@ type of content by checking the word boundary's existence."
 (defcustom ts-fold-summary-parsers-alist
   `((actionscript-mode . ts-fold-summary-javadoc)
     (bat-mode          . ts-fold-summary-batch)
+    (beancount-mode    . ts-fold-summary-elisp)
     (c-mode            . ts-fold-summary-c)
     (c++-mode          . ts-fold-summary-c)
     (clojure-mode      . ts-fold-summary-elisp)
diff --git a/ts-fold.el b/ts-fold.el
index 4f980bcaf7..2aa2969981 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -60,6 +60,7 @@
 ;; alphabetically sorted
 (defcustom ts-fold-range-alist
   `((agda-mode       . ,(ts-fold-parsers-agda))
+    (beancount-mode  . ,(ts-fold-parsers-beancount))
     (c-mode          . ,(ts-fold-parsers-c))
     (c++-mode        . ,(ts-fold-parsers-c++))
     (caml-mode       . ,(ts-fold-parsers-ocaml))
@@ -494,6 +495,16 @@ more information."
 ;; (@* "Languages" )
 ;;
 
+(defun ts-fold-range-beancount-transaction (node offset)
+  "Define fold range for `transaction' preprocessor.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let* ((beg (tsc-node-start-position node))
+              (beg (save-excursion (goto-char beg) (line-end-position)))
+              (end (1- (tsc-node-end-position node))))
+    (ts-fold--cons-add (cons beg end) offset)))
+
 (defun ts-fold-range-c-preproc-if (node offset)
   "Define fold range for `if' preprocessor.
 
@@ -545,6 +556,39 @@ more information."
               (end (1- (tsc-node-start-position next))))
     (ts-fold--cons-add (cons beg end) offset)))
 
+(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-elisp-function (node offset)
+  "Return the fold range for `macro_definition' and `function_definition' NODE
+in Elisp.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (when-let* ((param-node (tsc-get-nth-child node 4))
+              (beg (tsc-node-start-position param-node))
+              (end (1- (tsc-node-end-position node))))
+    (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* ((end-child (ts-fold-last-child node))
+              (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)))
+
 (defun ts-fold-range-haskell-function (node offset)
   "Define fold range for `function' in Haskell.
 
@@ -566,6 +610,120 @@ more information."
          (end (tsc-node-start-position end-node)))
     (ts-fold--cons-add (cons beg end) offset)))
 
+(defun ts-fold-range-julia (node offset)
+  "Return the fold range for a NODE in Julia.
+
+It excludes the NODE's first child and the `end' keyword.  For
+argument OFFSET, see function `ts-fold-range-seq' for more
+information."
+  (let* ((identifier (tsc-get-nth-named-child node 0))
+         (end-position (byte-to-position (aref (tsc-node-range identifier) 1)))
+         (start-position (byte-to-position (aref (tsc-node-range node) 0)))
+         (fold-begin (1- (- end-position start-position))))
+    (ts-fold-range-seq node (ts-fold--cons-add (cons fold-begin -2) offset))))
+
+(defun ts-fold-range-kotlin-when (node offset)
+  "Return the fold range for `when' NODE in Kotlin.
+
+It excludes the NODE's first child and the `end' keyword.  For
+argument OFFSET, see function `ts-fold-range-seq' for more
+information."
+  (when-let* ((open-bracket (car (ts-fold-find-children node "{")))
+              (beg (tsc-node-end-position open-bracket))
+              (end (1- (tsc-node-end-position node))))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-comment (node offset)
+  "Define fold range for Lua comemnt.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let ((text (tsc-node-text node)))
+    (if (and (string-match-p "\n" text) (string-prefix-p "--[[" text))
+        (ts-fold-range-block-comment node
+                                     ;; XXX: Add 2 to for ]] at the end
+                                     (ts-fold--cons-add (cons 2 0) offset))
+      (ts-fold-range-line-comment node offset "--"))))
+
+(defun ts-fold-range-lua-function (node offset)
+  "Define fold range for Lua `function' declaration.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((params (tsc-get-child-by-field node :parameters))
+         (beg (tsc-node-end-position params))
+         (end (- (tsc-node-end-position node) 3)))  ; fit identifier `end'
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-if (node offset)
+  "Define fold range for Lua `if' statement.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((then (car (ts-fold-find-children node "then")))
+         (beg (tsc-node-end-position then))
+         (next (or (ts-fold-find-children-traverse node "elseif_statement")
+                   (ts-fold-find-children-traverse node "else_statement")))
+         (end (if next
+                  (tsc-node-start-position (car next))
+                (- (tsc-node-end-position node) 3))))
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-elseif (node offset)
+  "Define fold range for Lua `elseif' statement.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((then (car (ts-fold-find-children node "then")))
+         (beg (tsc-node-end-position then))
+         (next (tsc-get-next-sibling node))
+         (end (if next
+                  (tsc-node-start-position next)
+                (tsc-node-end-position node))))
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-else (node offset)
+  "Define fold range for Lua `else' statement.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((beg (+ (tsc-node-start-position node) 4))  ; fit `else', 4 letters
+         (next (tsc-get-next-sibling node))          ; the `end' node
+         (end (tsc-node-start-position next)))
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-do-loop (node offset)
+  "Define fold range for Lua `while' and `for' statement.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((do (car (ts-fold-find-children node "do")))
+         (beg (tsc-node-end-position do))
+         (end (- (tsc-node-end-position node) 3)))
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-lua-repeat (node offset)
+  "Define fold range for Lua `repeat' statement.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+  (let* ((beg (+ (tsc-node-start-position node) 6))  ; fit `repeat', 6 letters
+         (until (car (ts-fold-find-children node "until")))
+         (end (tsc-node-start-position until)))
+    (when ts-fold-on-next-line  ; display nicely
+      (setq end (ts-fold-point-before-line-break end)))
+    (ts-fold--cons-add (cons beg end) offset)))
+
 ;;+ OCaml
 
 (defun ts-fold-range-ocaml-comment (node offset)
@@ -629,17 +787,6 @@ 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'.
 
@@ -705,142 +852,6 @@ more information."
               (end (1+ (tsc-node-start-position last_bracket))))
     (ts-fold--cons-add (cons beg end) offset)))
 
-(defun ts-fold-range-elisp-function (node offset)
-  "Return the fold range for `macro_definition' and `function_definition' NODE
-in Elisp.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (when-let* ((param-node (tsc-get-nth-child node 4))
-              (beg (tsc-node-start-position param-node))
-              (end (1- (tsc-node-end-position node))))
-    (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* ((end-child (ts-fold-last-child node))
-              (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)))
-
-(defun ts-fold-range-julia (node offset)
-  "Return the fold range for a NODE in Julia.
-
-It excludes the NODE's first child and the `end' keyword.  For
-argument OFFSET, see function `ts-fold-range-seq' for more
-information."
-  (let* ((identifier (tsc-get-nth-named-child node 0))
-         (end-position (byte-to-position (aref (tsc-node-range identifier) 1)))
-         (start-position (byte-to-position (aref (tsc-node-range node) 0)))
-         (fold-begin (1- (- end-position start-position))))
-    (ts-fold-range-seq node (ts-fold--cons-add (cons fold-begin -2) offset))))
-
-(defun ts-fold-range-kotlin-when (node offset)
-  "Return the fold range for `when' NODE in Kotlin.
-
-It excludes the NODE's first child and the `end' keyword.  For
-argument OFFSET, see function `ts-fold-range-seq' for more
-information."
-  (when-let* ((open-bracket (car (ts-fold-find-children node "{")))
-              (beg (tsc-node-end-position open-bracket))
-              (end (1- (tsc-node-end-position node))))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-comment (node offset)
-  "Define fold range for Lua comemnt.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let ((text (tsc-node-text node)))
-    (if (and (string-match-p "\n" text) (string-prefix-p "--[[" text))
-        (ts-fold-range-block-comment node
-                                     ;; XXX: Add 2 to for ]] at the end
-                                     (ts-fold--cons-add (cons 2 0) offset))
-      (ts-fold-range-line-comment node offset "--"))))
-
-(defun ts-fold-range-lua-function (node offset)
-  "Define fold range for Lua `function' declaration.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((params (tsc-get-child-by-field node :parameters))
-         (beg (tsc-node-end-position params))
-         (end (- (tsc-node-end-position node) 3)))  ; fit identifier `end'
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-if (node offset)
-  "Define fold range for Lua `if' statement.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((then (car (ts-fold-find-children node "then")))
-         (beg (tsc-node-end-position then))
-         (next (or (ts-fold-find-children-traverse node "elseif_statement")
-                   (ts-fold-find-children-traverse node "else_statement")))
-         (end (if next
-                  (tsc-node-start-position (car next))
-                (- (tsc-node-end-position node) 3))))
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-elseif (node offset)
-  "Define fold range for Lua `elseif' statement.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((then (car (ts-fold-find-children node "then")))
-         (beg (tsc-node-end-position then))
-         (next (tsc-get-next-sibling node))
-         (end (if next
-                  (tsc-node-start-position next)
-                (tsc-node-end-position node))))
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-else (node offset)
-  "Define fold range for Lua `else' statement.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((beg (+ (tsc-node-start-position node) 4))  ; fit `else', 4 letters
-         (next (tsc-get-next-sibling node))          ; the `end' node
-         (end (tsc-node-start-position next)))
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-do-loop (node offset)
-  "Define fold range for Lua `while' and `for' statement.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((do (car (ts-fold-find-children node "do")))
-         (beg (tsc-node-end-position do))
-         (end (- (tsc-node-end-position node) 3)))
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
-(defun ts-fold-range-lua-repeat (node offset)
-  "Define fold range for Lua `repeat' statement.
-
-For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
-more information."
-  (let* ((beg (+ (tsc-node-start-position node) 6))  ; fit `repeat', 6 letters
-         (until (car (ts-fold-find-children node "until")))
-         (end (tsc-node-start-position until)))
-    (when ts-fold-on-next-line  ; display nicely
-      (setq end (ts-fold-point-before-line-break end)))
-    (ts-fold--cons-add (cons beg end) offset)))
-
 (defun ts-fold-range-toml-table (node offset)
   "Return the fold range for `table' NODE in TOML.
 



reply via email to

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