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

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

[nongnu] elpa/treesit-fold 3375b2939a: feat: Add Janet support (#22)


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 3375b2939a: feat: Add Janet support (#22)
Date: Mon, 2 Dec 2024 16:01:12 -0500 (EST)

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

    feat: Add Janet support (#22)
    
    * feat: Add Janet support
    
    * fix pr id
---
 CHANGELOG.md            |  1 +
 README.md               | 54 +++++++++++++--------------
 treesit-fold-parsers.el |  8 ++++
 treesit-fold-summary.el |  1 +
 treesit-fold.el         | 99 +++++++++++++++++++++++++------------------------
 5 files changed, 87 insertions(+), 76 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a70c30a31b..0a619044fd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 
 * feat: Add `HEEx` support (#19)
 * feat: Add `EditorConfig` support (#20)
+* feat: Add `Janet` support (#22)
 
 ## 0.1.0
 > Released Jun 22, 2024
diff --git a/README.md b/README.md
index f8ffc0eb02..fe03650a45 100644
--- a/README.md
+++ b/README.md
@@ -20,33 +20,33 @@ the tree-sitter syntax tree.
 <!-- markdown-toc start - Don't edit this section. Run M-x 
markdown-toc-refresh-toc -->
 **Table of Contents**
 
-- [💾 Installation](#💾-installation)
-  - [🔍 Method 1. with `straight.el` and 
`use-package`:](#🔍-method-1-with-straightel-and-use-package)
-  - [🔍 Method 2. Manual](#🔍-method-2-manual)
-- [🖥 Usage](#🖥-usage)
-  - [📇 Commands](#📇-commands)
-  - [🔨 Supported languages](#🔨-supported-languages)
-    - [🚀 Add support for non-ts modes](#🚀-Add-support-for-non-ts-modes)
-- [📝 Customization](#📝-customization)
-  - [⚪ Folding on new nodes](#⚪-folding-on-new-nodes)
-    - [❔ Example](#❔-example)
+- [💾 Installation](#-installation)
+  - [🔍 Method 1. with `straight.el` and 
`use-package`:](#-method-1-with-straightel-and-use-package)
+  - [🔍 Method 2. Manual](#-method-2-manual)
+- [🖥 Usage](#-usage)
+  - [📇 Commands](#-commands)
+  - [🔨 Supported languages](#-supported-languages)
+    - [🚀 Add support for non-ts modes](#-add-support-for-non-ts-modes)
+- [📝 Customization](#-customization)
+  - [⚪ Folding on new nodes](#-folding-on-new-nodes)
+    - [❔ Example](#-example)
     - [↔ Offset](#-offset)
-  - [🔍 Writing new fold functions](#🔍-writing-new-fold-functions)
-- [🔌 Plugins](#🔌-plugins)
-  - [⚖ Indicators Mode](#⚖-indicators-mode)
-    - [💾 Installation](#💾-installation-1)
-    - [🖥 Usage](#🖥-usage-1)
-  - [📝 Summary](#📝-summary)
-    - [🖥 Usage](#🖥-usage-2)
-    - [📝 Customization](#📝-customization-1)
-  - [🌫 Line-Comment folding](#🌫-line-comment-folding)
-    - [🖥 Usage](#🖥-usage-3)
-- [🔰 Contribute](#🔰-contribute)
-  - [🔬 Development](#🔬-development)
-  - [❓ How to add a folding parser?](#❓-how-to-add-a-folding-parser)
-    - [🔍 Where can I look for tree-sitter 
node?](#🔍-where-can-i-look-for-tree-sitter-node)
-  - [❓ How to create a summary parser?](#❓-how-to-create-a-summary-parser)
-- [⚜️ License](#⚜️-license)
+  - [🔍 Writing new fold functions](#-writing-new-fold-functions)
+- [🔌 Plugins](#-plugins)
+  - [⚖ Indicators Mode](#-indicators-mode)
+    - [💾 Installation](#-installation-1)
+    - [🖥 Usage](#-usage-1)
+  - [📝 Summary](#-summary)
+    - [🖥 Usage](#-usage-2)
+    - [📝 Customization](#-customization-1)
+  - [🌫 Line-Comment folding](#-line-comment-folding)
+    - [🖥 Usage](#-usage-3)
+- [🔰 Contribute](#-contribute)
+  - [🔬 Development](#-development)
+  - [❓ How to add a folding parser?](#-how-to-add-a-folding-parser)
+    - [🔍 Where can I look for tree-sitter 
node?](#-where-can-i-look-for-tree-sitter-node)
+  - [❓ How to create a summary parser?](#-how-to-create-a-summary-parser)
+- [⚜️ License](#-license)
 
 <!-- markdown-toc end -->
 
@@ -122,7 +122,7 @@ These languages are fairly complete:
 - Fish
 - GDScript / Gleam / GLSL / Go / Groovy (Jenkinsfile)
 - Haskell / Haxe / HEEx / HLSL / HTML
-- Jai / Java / JavaScript / JSX / JSON / Jsonnet / Julia
+- Jai / Janet / Java / JavaScript / JSX / JSON / Jsonnet / Julia
 - Kotlin
 - LaTex / Lisp / Lua
 - Make / MATLAB / Markdown / Mermaid
diff --git a/treesit-fold-parsers.el b/treesit-fold-parsers.el
index cb585363c3..3d813393c8 100644
--- a/treesit-fold-parsers.el
+++ b/treesit-fold-parsers.el
@@ -348,6 +348,14 @@
     (block_comment    . treesit-fold-range-block-comment)
     (inline_comment   . treesit-fold-range-c-like-comment)))
 
+(defun treesit-fold-parsers-janet ()
+  "Rule set for Janet."
+  '((par_tup_lit . treesit-fold-range-seq)
+    (sqr_tup_lit . treesit-fold-range-seq)
+    (comment
+     . (lambda (node offset)
+         (treesit-fold-range-line-comment node offset "#")))))
+
 (defun treesit-fold-parsers-java ()
   "Rule set for Java."
   '((switch_block                    . treesit-fold-range-seq)
diff --git a/treesit-fold-summary.el b/treesit-fold-summary.el
index e03a1f4ff4..22559c8487 100644
--- a/treesit-fold-summary.el
+++ b/treesit-fold-summary.el
@@ -223,6 +223,7 @@ type of content by checking the word boundary's existence."
     (hlsl-mode              . treesit-fold-summary-c)
     (html-mode              . treesit-fold-summary-xml)
     (jai-mode               . treesit-fold-summary-c)
+    (janet-mode             . treesit-fold-summary-ruby-doc)
     (java-mode              . treesit-fold-summary-javadoc)
     (javascript-mode        . treesit-fold-summary-javadoc)
     (js-mode                . treesit-fold-summary-javadoc)
diff --git a/treesit-fold.el b/treesit-fold.el
index 3b2601dd89..010155cef2 100644
--- a/treesit-fold.el
+++ b/treesit-fold.el
@@ -114,6 +114,7 @@
     (html-mode              . ,(treesit-fold-parsers-html))
     (html-ts-mode           . ,(treesit-fold-parsers-html))
     (jai-mode               . ,(treesit-fold-parsers-jai))
+    (janet-mode             . ,(treesit-fold-parsers-janet))
     (java-mode              . ,(treesit-fold-parsers-java))
     (java-ts-mode           . ,(treesit-fold-parsers-java))
     (javascript-mode        . ,(treesit-fold-parsers-javascript))
@@ -478,14 +479,14 @@ current `major-mode'.
 If no NODE is found in point, do nothing."
   (interactive)
   (treesit-fold--ensure-ts
-    (when-let* ((node (or node (treesit-fold--foldable-node-at-pos))))
-      ;; make sure I do not create multiple overlays for the same fold
-      (when-let* ((ov (treesit-fold-overlay-at node)))
-        (delete-overlay ov))
-      (when-let* ((range (treesit-fold--get-fold-range node))
-                  (ov (treesit-fold--create-overlay range)))
-        (run-hooks 'treesit-fold-on-fold-hook)
-        ov))))
+   (when-let* ((node (or node (treesit-fold--foldable-node-at-pos))))
+     ;; make sure I do not create multiple overlays for the same fold
+     (when-let* ((ov (treesit-fold-overlay-at node)))
+       (delete-overlay ov))
+     (when-let* ((range (treesit-fold--get-fold-range node))
+                 (ov (treesit-fold--create-overlay range)))
+       (run-hooks 'treesit-fold-on-fold-hook)
+       ov))))
 
 ;;;###autoload
 (defun treesit-fold-open ()
@@ -493,58 +494,58 @@ If no NODE is found in point, do nothing."
 If the current node is not folded or not foldable, do nothing."
   (interactive)
   (treesit-fold--ensure-ts
-    (when-let* ((node (treesit-fold--foldable-node-at-pos))
-                (ov (treesit-fold-overlay-at node)))
-      (delete-overlay ov)
-      (run-hooks 'treesit-fold-on-fold-hook)
-      t)))
+   (when-let* ((node (treesit-fold--foldable-node-at-pos))
+               (ov (treesit-fold-overlay-at node)))
+     (delete-overlay ov)
+     (run-hooks 'treesit-fold-on-fold-hook)
+     t)))
 
 ;;;###autoload
 (defun treesit-fold-open-recursively ()
   "Open recursively folded syntax NODE that are contained in the node at 
point."
   (interactive)
   (treesit-fold--ensure-ts
-    (when-let* ((node (treesit-fold--foldable-node-at-pos))
-                (beg (treesit-node-start node))
-                (end (treesit-node-end node))
-                (nodes (treesit-fold--overlays-in 'invisible 'treesit-fold beg 
end)))
-      (mapc #'delete-overlay nodes)
-      (run-hooks 'treesit-fold-on-fold-hook)
-      t)))
+   (when-let* ((node (treesit-fold--foldable-node-at-pos))
+               (beg (treesit-node-start node))
+               (end (treesit-node-end node))
+               (nodes (treesit-fold--overlays-in 'invisible 'treesit-fold beg 
end)))
+     (mapc #'delete-overlay nodes)
+     (run-hooks 'treesit-fold-on-fold-hook)
+     t)))
 
 ;;;###autoload
 (defun treesit-fold-close-all ()
   "Fold all foldable syntax nodes in the buffer."
   (interactive)
   (treesit-fold--ensure-ts
-    (let (nodes)
-      (let* ((treesit-fold-indicators-mode)
-             (treesit-fold-on-fold-hook)
-             (node (treesit-buffer-root-node))
-             (patterns (seq-mapcat (lambda (fold-range) `((,(car fold-range)) 
@name))
-                                   (alist-get major-mode 
treesit-fold-range-alist)))
-             (query (treesit-query-compile (treesit-node-language node) 
patterns)))
-        (setq nodes (treesit-query-capture node query)
-              nodes (cl-remove-if (lambda (node)
-                                    ;; Removed if on same line
-                                    (treesit-fold--node-range-on-same-line 
(cdr node)))
-                                  nodes))
-        (thread-last nodes
-                     (mapcar #'cdr)
-                     (mapc #'treesit-fold-close)))
-      (when nodes
-        (run-hooks 'treesit-fold-on-fold-hook)
-        t))))
+   (let (nodes)
+     (let* ((treesit-fold-indicators-mode)
+            (treesit-fold-on-fold-hook)
+            (node (treesit-buffer-root-node))
+            (patterns (seq-mapcat (lambda (fold-range) `((,(car fold-range)) 
@name))
+                                  (alist-get major-mode 
treesit-fold-range-alist)))
+            (query (treesit-query-compile (treesit-node-language node) 
patterns)))
+       (setq nodes (treesit-query-capture node query)
+             nodes (cl-remove-if (lambda (node)
+                                   ;; Removed if on same line
+                                   (treesit-fold--node-range-on-same-line (cdr 
node)))
+                                 nodes))
+       (thread-last nodes
+                    (mapcar #'cdr)
+                    (mapc #'treesit-fold-close)))
+     (when nodes
+       (run-hooks 'treesit-fold-on-fold-hook)
+       t))))
 
 ;;;###autoload
 (defun treesit-fold-open-all ()
   "Unfold all syntax nodes in the buffer."
   (interactive)
   (treesit-fold--ensure-ts
-    (when-let* ((nodes (treesit-fold--overlays-in 'invisible 'treesit-fold)))
-      (mapc #'delete-overlay nodes)
-      (run-hooks 'treesit-fold-on-fold-hook)
-      t)))
+   (when-let* ((nodes (treesit-fold--overlays-in 'invisible 'treesit-fold)))
+     (mapc #'delete-overlay nodes)
+     (run-hooks 'treesit-fold-on-fold-hook)
+     t)))
 
 ;;;###autoload
 (defun treesit-fold-toggle ()
@@ -552,13 +553,13 @@ If the current node is not folded or not foldable, do 
nothing."
 If the current syntax node is not foldable, do nothing."
   (interactive)
   (treesit-fold--ensure-ts
-    (if-let* ((node (treesit-fold--foldable-node-at-pos (point)))
-              (ov (treesit-fold-overlay-at node)))
-        (progn
-          (delete-overlay ov)
-          (run-hooks 'treesit-fold-on-fold-hook)
-          t)
-      (treesit-fold-close))))
+   (if-let* ((node (treesit-fold--foldable-node-at-pos (point)))
+             (ov (treesit-fold-overlay-at node)))
+       (progn
+         (delete-overlay ov)
+         (run-hooks 'treesit-fold-on-fold-hook)
+         t)
+     (treesit-fold-close))))
 
 (defun treesit-fold--after-command (&rest _)
   "Function call after interactive commands."



reply via email to

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