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

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

[nongnu] elpa/treesit-fold 4cfea19d1f 2/2: feat: Add EditorConfig suppor


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 4cfea19d1f 2/2: feat: Add EditorConfig support (#20)
Date: Wed, 20 Nov 2024 16:00:47 -0500 (EST)

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

    feat: Add EditorConfig support (#20)
    
    * feat: Add EditorConfig support
    
    * Changelog
---
 CHANGELOG.md            |  3 ++-
 treesit-fold-parsers.el | 10 ++++++++++
 treesit-fold-summary.el |  3 ++-
 treesit-fold.el         | 21 +++++++++++++++++++++
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f88ed024f..a70c30a31b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 ## 0.2.0 (Unreleased)
 > Released N/A
 
-* feat: Add HEEx support (#19)
+* feat: Add `HEEx` support (#19)
+* feat: Add `EditorConfig` support (#20)
 
 ## 0.1.0
 > Released Jun 22, 2024
diff --git a/treesit-fold-parsers.el b/treesit-fold-parsers.el
index f1fd2faf83..cb585363c3 100644
--- a/treesit-fold-parsers.el
+++ b/treesit-fold-parsers.el
@@ -87,6 +87,7 @@
 (declare-function treesit-fold-range-org-body "treesit-fold.el")
 (declare-function treesit-fold-range-clojure-function "treesit-fold.el")
 (declare-function treesit-fold-range-cmake-body "treesit-fold.el")
+(declare-function treesit-fold-range-editorconfig-section "treesit-fold.el")
 (declare-function treesit-fold-range-pascal-comment "treesit-fold.el")
 (declare-function treesit-fold-range-python-def "treesit-fold.el")
 (declare-function treesit-fold-range-python-expression-statement 
"treesit-fold.el")
@@ -221,6 +222,15 @@
     (documentation_comment . treesit-fold-range-c-like-comment)
     (list_literal          . treesit-fold-range-seq)))  ; array
 
+(defun treesit-fold-parsers-editorconfig ()
+  "Rule set for EditorConfig."
+  '((section . treesit-fold-range-editorconfig-section)
+    (comment
+     . (lambda (node offset)
+         (treesit-fold-range-line-comment node
+                                          (treesit-fold--cons-add offset '(0 . 
-1))
+                                          "#")))))
+
 (defun treesit-fold-parsers-elisp ()
   "Rule set for Elisp."
   '((macro_definition    . treesit-fold-range-elisp-function)
diff --git a/treesit-fold-summary.el b/treesit-fold-summary.el
index c1c2212453..e87cc0547e 100644
--- a/treesit-fold-summary.el
+++ b/treesit-fold-summary.el
@@ -59,7 +59,7 @@ This happens only when summary length is larger than variable
 (define-obsolete-variable-alias
   'treesit-fold-summary-exceeded-string
   'truncate-string-ellipsis
-  "treesit-fold 0.4.0"
+  "treesit-fold 0.2.0"
   "Use built-in variable instead.")
 
 ;;
@@ -224,6 +224,7 @@ type of content by checking the word boundary's existence."
     (csharp-mode            . treesit-fold-summary-csharp)
     (css-mode               . treesit-fold-summary-javadoc)
     (dart-mode              . treesit-fold-summary-javadoc)
+    (editorconfig-conf-mode . treesit-fold-summary-ruby-doc)
     (emacs-lisp-mode        . treesit-fold-summary-elisp)
     (elixir-mode            . treesit-fold-summary-ruby-doc)
     (erlang-mode            . treesit-fold-summary-tex-doc)
diff --git a/treesit-fold.el b/treesit-fold.el
index 715193314d..3b2601dd89 100644
--- a/treesit-fold.el
+++ b/treesit-fold.el
@@ -64,6 +64,7 @@
     (asm-mode               . ,(treesit-fold-parsers-asm))
     (awk-mode               . ,(treesit-fold-parsers-awk))
     (awk-ts-mode            . ,(treesit-fold-parsers-awk))
+    (editorconfig-conf-mode . ,(treesit-fold-parsers-editorconfig))
     (fasm-mode              . ,(treesit-fold-parsers-asm))
     (masm-mode              . ,(treesit-fold-parsers-asm))
     (nasm-mode              . ,(treesit-fold-parsers-asm))
@@ -794,6 +795,26 @@ more information."
       (setq end (treesit-fold--last-eol end)))
     (treesit-fold--cons-add (cons beg end) offset)))
 
+(defun treesit-fold-range-editorconfig-end-section (node)
+  "Return the section NODE's end point."
+  (let ((pt (treesit-node-end node))
+        (children (reverse (treesit-node-children node))))
+    (cl-some (lambda (child)
+               (when (equal 'pair (treesit-node-type child))
+                 (setq pt (treesit-node-end child))))
+             children)
+    pt))
+
+(defun treesit-fold-range-editorconfig-section (node offset)
+  "Return the fold range for `section' NODE in EditorConfig.
+
+For arguments NODE and OFFSET, see function `treesit-fold-range-seq' for
+more information."
+  (when-let* ((end-bracket (car (treesit-fold-find-children node "]")))
+              (beg (treesit-node-end end-bracket))
+              (end (1- (treesit-fold-range-editorconfig-end-section node))))
+    (treesit-fold--cons-add (cons beg end) offset)))
+
 (defun treesit-fold-range-elisp-function (node offset)
   "Return the fold range for `macro_definition' and `function_definition' NODE
 in Elisp.



reply via email to

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