[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 22ffb18db6 303/417: feat: Add Pascal support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 22ffb18db6 303/417: feat: Add Pascal support (#85) |
Date: |
Mon, 1 Jul 2024 10:02:43 -0400 (EDT) |
branch: elpa/treesit-fold
commit 22ffb18db61a8defc3e091bbb9a774263298cd82
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>
feat: Add Pascal support (#85)
* feat: Add Pascal support
* basic
* fix checkdoc
---
CHANGELOG.md | 1 +
README.md | 1 +
ts-fold-parsers.el | 5 +++++
ts-fold-summary.el | 7 +++++++
ts-fold.el | 51 +++++++++++++++++++++++++++++++++++++++++----------
5 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f1e1e7546..3c6713d927 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for
recommendations on how
* Add Jsonnet support (#81)
* Add Zig support (#82)
* Add Erlang support (#83)
+* Add basic Pascal support (#84)
## 0.2.0
> Released Sep 01, 2023
diff --git a/README.md b/README.md
index 6626109eb6..c820e40e46 100644
--- a/README.md
+++ b/README.md
@@ -138,6 +138,7 @@ These languages are in development:
- Ada
- Agda
- Elm
+- Pascal
## 📝 Customization
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 697432af3d..e666b21bbc 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -62,6 +62,7 @@
(declare-function ts-fold-range-lua-repeat "ts-fold.el")
(declare-function ts-fold-range-ocaml "ts-fold.el")
(declare-function ts-fold-range-clojure-function "ts-fold.el")
+(declare-function ts-fold-range-pascal-comment "ts-fold.el")
(declare-function ts-fold-range-python-def "ts-fold.el")
(declare-function ts-fold-range-python-expression-statement "ts-fold.el")
(declare-function ts-fold-range-ruby-class-def "ts-fold.el")
@@ -322,6 +323,10 @@
(type_definition . ts-fold-range-ocaml-type-definition)
(value_definition . ts-fold-range-ocaml-value-definition)))
+(defun ts-fold-parsers-pascal ()
+ "Rule set for Pascal."
+ '((comment . ts-fold-range-pascal-comment)))
+
(defun ts-fold-parsers-perl ()
"Rule set for Perl."
'((block . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 9e4f2e2145..22c2ce84f0 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -128,6 +128,12 @@ type of content by checking the word boundary's existence."
"Extract summary from DOC-STR in Lua."
(ts-fold-summary--generic doc-str "--"))
+(defun ts-fold-summary-pascal-doc (doc-str)
+ "Extract summary from DOC-STR in Pascal."
+ (cond ((string-prefix-p "{" doc-str)
+ (ts-fold-summary--generic doc-str '("{" "}")))
+ (t (ts-fold-summary-go doc-str))))
+
(defun ts-fold-summary-python-doc (doc-str)
"Extract summary from DOC-STR in Python."
(ts-fold-summary--generic doc-str "\"\"\""))
@@ -241,6 +247,7 @@ type of content by checking the word boundary's existence."
(org-mode . ts-fold-summary-org)
(perl-mode . ts-fold-summary-ruby-doc)
(php-mode . ts-fold-summary-javadoc)
+ (pascal-mode . ts-fold-summary-pascal-doc)
(python-mode . ts-fold-summary-python-doc)
(rjsx-mode . ts-fold-summary-javadoc)
(ruby-mode . ts-fold-summary-ruby-doc)
diff --git a/ts-fold.el b/ts-fold.el
index bfe5bd8790..1aebeecad0 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -93,6 +93,7 @@
(noir-mode . ,(ts-fold-parsers-noir))
(nix-mode . ,(ts-fold-parsers-nix))
(ocaml-mode . ,(ts-fold-parsers-ocaml))
+ (pascal-mode . ,(ts-fold-parsers-pascal))
(perl-mode . ,(ts-fold-parsers-perl))
(php-mode . ,(ts-fold-parsers-php))
(python-mode . ,(ts-fold-parsers-python))
@@ -234,6 +235,18 @@ ts-fold can act on."
;; (@* "Core" )
;;
+(defun ts-fold--range-on-same-line (range)
+ "Return non-nil if RANGE is on the same line."
+ (let ((beg (car range))
+ (end (cdr range))
+ (lbp) (lep))
+ (save-excursion
+ (goto-char beg)
+ (setq lbp (line-beginning-position)
+ lep (line-end-position)))
+ (and (<= lbp beg) (<= beg lep)
+ (<= lbp end) (<= end lep))))
+
(defun ts-fold--get-fold-range (node)
"Return the beginning (as buffer position) of fold for NODE.
Return nil if there is no fold to be made."
@@ -243,6 +256,13 @@ Return nil if there is no fold to be made."
((listp fold-func) (funcall (nth 0 fold-func) node (cons (nth 1
fold-func) (nth 2 fold-func))))
(t (user-error "Bad folding function for node")))))
+(defun ts-fold--foldable-node-p (node mode-ranges)
+ "Return non-nil if NODE is foldable in MODE-RANGES."
+ (or (not (alist-get (tsc-node-type node) mode-ranges)) ; Not registered,
continue.
+ (let ((range (ts-fold--get-fold-range node)))
+ (or (not range) ; Range not defined,
continue.
+ (ts-fold--range-on-same-line range))))) ; On same line,
continue.
+
(defun ts-fold--foldable-node-at-pos (&optional pos)
"Return the smallest foldable node at POS. If POS is nil, use `point'.
@@ -256,8 +276,7 @@ This function is borrowed from `tree-sitter-node-at-point'."
;; Used for looping
(current node))
(while (and current
- (or (not (alist-get (tsc-node-type current) mode-ranges))
- (not (ts-fold--get-fold-range current))))
+ (ts-fold--foldable-node-p current mode-ranges))
(setq current (tsc-get-parent current)))
current))
@@ -468,7 +487,6 @@ Argument PREFIX is the comment prefix in string."
(when-let* ((ts-fold-line-comment-mode) ; XXX: Check enabled!?
(first-node (ts-fold--continuous-node-prefix node prefix nil))
(last-node (ts-fold--continuous-node-prefix node prefix t))
- ((not (equal first-node last-node)))
(prefix-len (length prefix))
(beg (+ (tsc-node-start-position first-node) prefix-len))
(end (tsc-node-end-position last-node)))
@@ -823,6 +841,19 @@ more information."
;;- OCaml
+(defun ts-fold-range-pascal-comment (node offset)
+ "Define fold range for `comment' in Pascal.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (let ((text (tsc-node-text node)))
+ (cond ((string-prefix-p "{" text)
+ (ts-fold-range-seq node offset))
+ ((string-prefix-p "(*" text)
+ (ts-fold-range-seq node (ts-fold--cons-add '(1 . -1) offset)))
+ (t
+ (ts-fold-range-c-like-comment node offset)))))
+
(defun ts-fold-range-python-def (node offset)
"Define fold range for `function_definition' and `class_definition'.
@@ -878,7 +909,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-rust-macro (node offset)
- "Return the fold range for `macro_definition' NODE in Rust.
+ "Return the fold range for `macro_definition' in Rust.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -889,7 +920,7 @@ more information."
(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.
+ "Return the fold range for `table' in TOML.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -900,7 +931,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-initial-construct (node offset)
- "Return the fold range for `initial' NODE in Verilog.
+ "Return the fold range for `initial' in Verilog.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -914,7 +945,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-verilog-list (node offset)
- "Return the fold range for `list' NODE in Verilog.
+ "Return the fold range for `list' in Verilog.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -925,7 +956,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-verilog-module (node offset)
- "Return the fold range for `module' NODE in Verilog.
+ "Return the fold range for `module' in Verilog.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -939,7 +970,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-vhdl-package (node offset)
- "Return the fold range for `package' NODE in VHDL.
+ "Return the fold range for `package' in VHDL.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
@@ -953,7 +984,7 @@ more information."
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-vhdl-type (node offset)
- "Return the fold range for `type' NODE in VHDL.
+ "Return the fold range for `type' in VHDL.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
- [nongnu] elpa/treesit-fold cc31fb573b 399/417: docs: Update line-reminder config, (continued)
- [nongnu] elpa/treesit-fold cc31fb573b 399/417: docs: Update line-reminder config, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6bb13a51ce 401/417: docs: Changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ef32910994 379/417: Update package desc, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2d175b74ad 375/417: chore: Expose overlay's priority, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold b8ac9a81ca 387/417: fix: Ensure return t, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 930c5cd6de 333/417: feat: Add Mermaid support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 21bba126be 321/417: fix: Ensure refresh when window size changes, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 665e3f074c 376/417: feat: Support new LaTeX-mode, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 947fbec8b5 350/417: reordered the alists for alphabetical ordering, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ab81fe718e 389/417: feat(json): Fold comment, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 22ffb18db6 303/417: feat: Add Pascal support (#85),
ELPA Syncer <=
- [nongnu] elpa/treesit-fold aafc4c0a5f 373/417: Changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 47c58282f7 335/417: Release, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9cbc292502 394/417: fix: Use handle dependent, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold c7a9d62e4c 363/417: feat: Add Ninja support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2236641e53 397/417: chore: changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f2650076af 382/417: fix: Clean compile warngins, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 882c4faae8 271/417: fix(parsers): update nix definitions (#37), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold bb5bd2e31e 276/417: feat: Add Clojure support (#64), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold dcf6fdcb85 292/417: Bump version for next version, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold b52b33357e 300/417: feat: Add Erlang support (#83), ELPA Syncer, 2024/07/01