[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 9d18dee909 354/417: Added a matlab parser for
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 9d18dee909 354/417: Added a matlab parser for folding. |
Date: |
Mon, 1 Jul 2024 10:03:04 -0400 (EDT) |
branch: elpa/treesit-fold
commit 9d18dee90973a5405e6a5045ea1ee14e9fd872fe
Author: Nidish Narayanaa Balaji <nidbid@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>
Added a matlab parser for folding.
---
ts-fold-parsers.el | 13 +++++++++++++
ts-fold-summary.el | 1 +
ts-fold.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index f2d673aace..2519cf92fe 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -501,6 +501,19 @@
. (lambda (node offset)
(ts-fold-range-line-comment node offset "#")))))
+(defun ts-fold-parsers-matlab ()
+ "Rule set for MATLAB."
+ '((expression_list . ts-fold-range-seq)
+ (function_definition . ts-fold-range-matlab-function)
+ (class_definition . ts-fold-range-matlab-function)
+ (if_statement . ts-fold-range-matlab-statements)
+ (for_statement . ts-fold-range-matlab-statements)
+ (while_statement . ts-fold-range-matlab-statements)
+ (switch_statement . ts-fold-range-matlab-statements)
+ (try_statement . ts-fold-range-matlab-statements)
+ (comment . ts-fold-range-matlab-blocks)
+ ))
+
(defun ts-fold-parsers-qss ()
"Rule set for QSS."
(append (ts-fold-parsers-css)))
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 636deedbc7..1e9e9e2f75 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -283,6 +283,7 @@ type of content by checking the word boundary's existence."
(php-mode . ts-fold-summary-javadoc)
(pascal-mode . ts-fold-summary-pascal-doc)
(python-mode . ts-fold-summary-python-doc)
+ (matlab-mode . ts-fold-summary-matlab-doc)
(qss-mode . ts-fold-summary-css)
(rjsx-mode . ts-fold-summary-javadoc)
(rst-mode . ts-fold-summary-rst-doc)
diff --git a/ts-fold.el b/ts-fold.el
index 1210659697..77595a841e 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -110,6 +110,7 @@
(makefile-makepp-mode . ,(ts-fold-parsers-make))
(makefile-bsdmake-mode . ,(ts-fold-parsers-make))
(makefile-imake-mode . ,(ts-fold-parsers-make))
+ (matlab-mode . ,(ts-fold-parsers-matlab))
(markdown-mode . ,(ts-fold-parsers-markdown))
(matlab-mode . ,(ts-fold-parsers-matlab))
(mermaid-mode . ,(ts-fold-parsers-mermaid))
@@ -1154,6 +1155,55 @@ more information."
(end (tsc-node-end-position node)))
(ts-fold--cons-add (cons (+ beg 3) (- end 3)) offset)))
+(defun ts-fold-range-matlab-function (node offset)
+ "Define fold range for MATLAB function definitions.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((named-node (or (tsc-get-child-by-field node :superclass)
+ (tsc-get-child-by-field node :properties)
+ (tsc-get-child-by-field node :methods)
+ (tsc-get-child-by-field node :function_arguments)
+ (tsc-get-child-by-field node :function_output)
+ (tsc-get-child-by-field node :name)))
+ (beg (tsc-node-end-position (tsc-get-next-sibling named-node)))
+ (end (tsc-node-end-position node)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-matlab-statements (node offset)
+ "Define fold range for MATLAB statements.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-line-comment' for
+more information."
+ (when-let* ((named-node (car (ts-fold-find-children node "\n")))
+ (beg (tsc-node-start-position named-node))
+ (ins (append
+ (ts-fold-find-children node "catch_clause")
+ (ts-fold-find-children node "case_clause")
+ (ts-fold-find-children node "otherwise_clause")
+ (ts-fold-find-children node "elseif_clause")
+ (ts-fold-find-children node "else_clause")
+ (ts-fold-find-children node "end"))) ;; can include parts
maybe
+ (end (tsc-node-start-position (car (ts-fold-find-children node
"end")))))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-matlab-blocks (node offset)
+ "Define fold range for MATLAB blocks.
+
+Each block is delimited by a line starting with '%%'.
+For arguments NODE and OFFSET, see function `ts-fold-range-line-comment' for
+more information."
+ (when (string-prefix-p "%%" (ts-node-text node))
+ (let* ((beg (ts-node-end-position node))
+ (end (or (save-excursion
+ (progn (goto-char beg)
+ (when (re-search-forward "^\s*\^L%%" nil t)
+ (forward-line -1) (end-of-line)
+ (point))))
+ (ts-node-end-position (ts-get-parent node)))))
+ (message (format "%d %d" beg end))
+ (ts-fold--cons-add (cons beg end) offset))))
+
(defun ts-fold-range-rst-body (node offset)
"Define fold range for `body' in reStructuredText.
- [nongnu] elpa/treesit-fold 458903e88d 250/417: fix: Fix nil tree-sitter-node, (continued)
- [nongnu] elpa/treesit-fold 458903e88d 250/417: fix: Fix nil tree-sitter-node, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6ada31e372 251/417: changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fbb5510d5c 290/417: feat: Add LaTex support (#76), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 81dc9eff92 283/417: Update CHANGELOG.md, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f8df121f08 270/417: ci(dependabot): Maintain github-actions, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a474fd6b42 285/417: feat: Add Jai support (#71), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 27e8f44fb6 269/417: test: Emacs 29.1, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7110ff8943 287/417: feat: Add Scheme support (#73), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 999f295bf4 282/417: fix: Don't fold lint comment when only 1 line (#69), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold befad113c9 390/417: feat: Return node when closing, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9d18dee909 354/417: Added a matlab parser for folding.,
ELPA Syncer <=
- [nongnu] elpa/treesit-fold bfdba4f0a8 339/417: fix PR id, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 56c19e3b2d 351/417: chore: Update changelog and README regarding dev, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 37715b54ee 309/417: feat: Add reStructuredText support (#89), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a54a3c92fd 315/417: feat: Add GLSL support (#94), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 1827d0aa9e 319/417: perf: Render indicators in display range (#97), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 0d602a06b1 378/417: Rename ts-fold to treesit-fold, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicators on non foldable node, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold db6cd0ae4f 352/417: style: Ensure spaces, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 4b35e27148 311/417: feat: Add SQL support (#91), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d1b07c7bb0 320/417: Update CHANGELOG.md, ELPA Syncer, 2024/07/01