[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.
- [nongnu] elpa/treesit-fold c408ef1165 291/417: Bump version - 0.2.0, (continued)
- [nongnu] elpa/treesit-fold c408ef1165 291/417: Bump version - 0.2.0, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e88e2579b6 191/417: Merge pull request #7 from Kaligule/patch-2, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e6191cb5ca 210/417: doc, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2bcb2f3ccf 213/417: Fix typo, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7f1e24cf23 215/417: Add todo note, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f0804a2435 230/417: docs(CHANGELOG): update (#28), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 74af83d2aa 239/417: Add default script directive, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 3e1a96dad0 241/417: Remove redundant fold node alist (#36), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2970338c7f 273/417: docs(README.md): Add Dart support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fe64d0e9d1 274/417: fix: Fold class in Dart, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 8734a2e2a8 288/417: feat: Add Beancount support (#74),
ELPA Syncer <=
- [nongnu] elpa/treesit-fold c515c18e84 388/417: feat: Fold script and style tag, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold b5664b1c1c 306/417: feat: Add Assembly support (#87), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a860af5c66 302/417: feat(ts): Include more rules for TS, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 58adaef135 328/417: Support k8s-mode, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e82256dd27 393/417: fix: missing treesit prefix, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d705c12059 299/417: feat: Add Zig support (#82), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7a7bd70185 295/417: feat: Add VHDL support (#79), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 0c13c0e4ed 374/417: ci: Bump Emacs 29.x to 3, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e015c9a3eb 297/417: feat: Add Jsonnet support (#81), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d50f5dd2f8 398/417: feat(parser): Add token_tree to Rust, ELPA Syncer, 2024/07/01