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

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

[nongnu] elpa/treesit-fold be2b3dd211 275/417: feat: Add Elisp support (


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold be2b3dd211 275/417: feat: Add Elisp support (#63)
Date: Mon, 1 Jul 2024 10:02:34 -0400 (EDT)

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

    feat: Add Elisp support (#63)
    
    * feat: Add Elisp support
    
    * changelog
    
    * Add elisp
---
 CHANGELOG.md       |  1 +
 README.md          |  3 +--
 ts-fold-parsers.el |  9 +++++++++
 ts-fold-summary.el |  5 +++++
 ts-fold.el         | 12 ++++++++++++
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d11d505db7..291a43c9d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for 
recommendations on how
 * Add support for Lua (#52)
 * Add support for Python docstring (#58)
 * Add Dart support (#62)
+* Add Elisp support (#63)
 
 ## 0.1.0
 > Released Oct 18, 2021
diff --git a/README.md b/README.md
index aa833889c0..698a8e6a3c 100644
--- a/README.md
+++ b/README.md
@@ -115,7 +115,7 @@ These languages are fairly complete:
 - Bash
 - C / C++ / C# / CSS
 - Dart
-- Elixir
+- Elisp / Elixir
 - Go
 - HTML
 - Java / JavaScript / JSX / JSON / Julia
@@ -131,7 +131,6 @@ These languages are in development:
 
 - Agda
 - Elm
-- Emacs Lisp
 - OCaml
 - XML (upstream)
 
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index b9f5e9654c..f98c77a27b 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -59,6 +59,7 @@
 (declare-function ts-fold-range-ruby-class-def "ts-fold.el")
 (declare-function ts-fold-range-ruby-if "ts-fold.el")
 (declare-function ts-fold-range-rust-macro "ts-fold.el")
+(declare-function ts-fold-range-elisp-function "ts-fold.el")
 (declare-function ts-fold-range-elixir "ts-fold.el")
 
 ;;
@@ -127,6 +128,14 @@
     (documentation_comment . ts-fold-range-c-like-comment)
     (list_literal          . ts-fold-range-seq)))  ; array
 
+(defun ts-fold-parsers-elisp ()
+  "Rule set for Elisp."
+  '((macro_definition    . ts-fold-range-elisp-function)
+    (function_definition . ts-fold-range-elisp-function)
+    (comment
+     . (lambda (node offset)
+         (ts-fold-range-line-comment node offset ";;")))))
+
 (defun ts-fold-parsers-elixir ()
   "Rules set for Elixir."
   '((list . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 75e6217e1d..4bf0532380 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -112,6 +112,10 @@ type of content by checking the word boundary's existence."
          (ts-fold-summary-csharp-vsdoc doc-str))
         (t (ts-fold-summary-javadoc doc-str))))
 
+(defun ts-fold-summary-elisp (doc-str)
+  "Extract summary from DOC-STR in Elisp."
+  (ts-fold-summary--generic doc-str ";;"))
+
 (defun ts-fold-summary-javadoc (doc-str)
   "Extract summary from DOC-STR in Javadoc."
   (ts-fold-summary--generic doc-str "*"))
@@ -206,6 +210,7 @@ type of content by checking the word boundary's existence."
     (csharp-mode       . ts-fold-summary-csharp)
     (css-mode          . ts-fold-summary-javadoc)
     (dart-mode         . ts-fold-summary-javadoc)
+    (emacs-lisp-mode   . ts-fold-summary-elisp)
     (go-mode           . ts-fold-summary-go)
     (html-mode         . ts-fold-summary-xml)
     (java-mode         . ts-fold-summary-javadoc)
diff --git a/ts-fold.el b/ts-fold.el
index fd32145ca1..77b8d48aa0 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -66,6 +66,7 @@
     (csharp-mode     . ,(ts-fold-parsers-csharp))
     (css-mode        . ,(ts-fold-parsers-css))
     (dart-mode       . ,(ts-fold-parsers-dart))
+    (emacs-lisp-mode . ,(ts-fold-parsers-elisp))
     (elixir-mode     . ,(ts-fold-parsers-elixir))
     (ess-r-mode      . ,(ts-fold-parsers-r))
     (go-mode         . ,(ts-fold-parsers-go))
@@ -669,6 +670,17 @@ 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.
 



reply via email to

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