[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 045841504e 059/417: Simplify node alist
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 045841504e 059/417: Simplify node alist |
Date: |
Mon, 1 Jul 2024 10:02:11 -0400 (EDT) |
branch: elpa/treesit-fold
commit 045841504e89435b9e569edb76391a56bcfbb8a9
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>
Simplify node alist
---
tree-sitter-fold-parsers.el | 30 +++++++++++++++++++++
tree-sitter-fold.el | 65 +++++++++++++++------------------------------
2 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/tree-sitter-fold-parsers.el b/tree-sitter-fold-parsers.el
index 7fafe4a204..e0fac123e0 100644
--- a/tree-sitter-fold-parsers.el
+++ b/tree-sitter-fold-parsers.el
@@ -41,5 +41,35 @@
""
(append (tree-sitter-fold-parsers-c)))
+(defun tree-sitter-fold-parsers-r ()
+ ""
+ '((brace_list . tree-sitter-fold-range-seq)))
+
+(defun tree-sitter-fold-parsers-go ()
+ ""
+ '((type_declaration . tree-sitter-fold-range-go-type-declaration)
+ (function_declaration . tree-sitter-fold-range-go-method)
+ (method_declaration . tree-sitter-fold-range-go-method)))
+
+(defun tree-sitter-fold-parsers-javascript ()
+ ""
+ '((export_clause . tree-sitter-fold-range-seq)
+ (statement_block . tree-sitter-fold-range-seq)))
+
+(defun tree-sitter-fold-parsers-nix ()
+ ""
+ '((attrset . tree-sitter-fold-range-nix-attrset)
+ (function . tree-sitter-fold-range-nix-function)))
+
+(defun tree-sitter-fold-parsers-python ()
+ ""
+ '((function_definition . tree-sitter-fold-range-python)
+ (class_definition . tree-sitter-fold-range-python)))
+
+(defun tree-sitter-fold-parsers-typescript ()
+ ""
+ (append (tree-sitter-fold-parsers-javascript)))
+
+
(provide 'tree-sitter-fold-parsers)
;;; tree-sitter-fold-parsers.el ends here
diff --git a/tree-sitter-fold.el b/tree-sitter-fold.el
index 9ade0c1fb8..2eb49c4202 100644
--- a/tree-sitter-fold.el
+++ b/tree-sitter-fold.el
@@ -55,51 +55,19 @@
:group 'tree-sitter
:prefix "tree-sitter-fold-")
-(defcustom tree-sitter-fold-foldable-node-alist
- '((c-mode . (compound_statement declaration_list enumerator_list
field_declaration_list comment))
- (c++-mode . (compound_statement declaration_list enumerator_list
field_declaration_list comment))
- (ess-r-mode . (brace_list))
- (go-mode . (type_declaration function_declaration
method_declaration))
- (javascript-mode . (export_clause))
- (js-mode . (export_clause))
- (js2-mode . (export_clause named_imports statement_block
switch_body object object_pattern))
- (js3-mode . (export_clause))
- (rjsx-mode . (export_clause named_imports statement_block
switch_body object object_pattern jsx_expression))
- (nix-mode . (attrset function))
- (python-mode . (function_definition class_definition))
- (typescript-mode . (export_clause)))
- "An alist of (mode . (list of tree-sitter-nodes considered foldable in this
mode))."
- :type '(alist :key-type symbol :value-type (repeat symbol))
- :group 'tree-sitter-fold)
-
(defcustom tree-sitter-fold-range-alist
- `((c-mode . ,(tree-sitter-fold-parsers-c))
- (c++-mode . ,(tree-sitter-fold-parsers-c++))
- (ess-r-mode
- . ((brace_list . tree-sitter-fold-range-seq)))
- (go-mode
- . ((type_declaration . tree-sitter-fold-range-go-type-declaration)
- (function_declaration . tree-sitter-fold-range-go-method)
- (method_declaration . tree-sitter-fold-range-go-method)))
- (javascript-mode
- . ((export_clause . tree-sitter-fold-range-seq)))
- (js-mode
- . ((export_clause . tree-sitter-fold-range-seq)))
- (js2-mode
- . ((export_clause . tree-sitter-fold-range-seq)
- (statement_block . tree-sitter-fold-range-seq)))
- (js3-mode
- . ((export_clause . tree-sitter-fold-range-seq)))
- (rjsx-mode
- . ((export_clause . tree-sitter-fold-range-seq)))
- (nix-mode
- . ((attrset . tree-sitter-fold-range-nix-attrset)
- (function . tree-sitter-fold-range-nix-function)))
- (python-mode
- . ((function_definition . tree-sitter-fold-range-python)
- (class_definition . tree-sitter-fold-range-python)))
- (typescript-mode
- . ((export_clause . tree-sitter-fold-range-seq))))
+ `((c-mode . ,(tree-sitter-fold-parsers-c))
+ (c++-mode . ,(tree-sitter-fold-parsers-c++))
+ (ess-r-mode . ,(tree-sitter-fold-parsers-r))
+ (go-mode . ,(tree-sitter-fold-parsers-go))
+ (javascript-mode . ,(tree-sitter-fold-parsers-javascript))
+ (js-mode . ,(tree-sitter-fold-parsers-javascript))
+ (js2-mode . ,(tree-sitter-fold-parsers-javascript))
+ (js3-mode . ,(tree-sitter-fold-parsers-javascript))
+ (rjsx-mode . ,(tree-sitter-fold-parsers-javascript))
+ (nix-mode . ,(tree-sitter-fold-parsers-nix))
+ (python-mode . ,(tree-sitter-fold-parsers-python))
+ (typescript-mode . ,(tree-sitter-fold-parsers-typescript)))
"An alist of (major-mode . (foldable-node-type . function)).
FUNCTION is used to determine where the beginning and end for
FOLDABLE-NODE-TYPE
@@ -110,6 +78,15 @@ the fold in a cons cell. See
`tree-sitter-fold-range-python' for an example."
:value-type (alist :key-type symbol :value-type function))
:group 'tree-sitter-fold)
+(defconst tree-sitter-fold-foldable-node-alist
+ (let (alist)
+ (dolist (item tree-sitter-fold-range-alist)
+ (let ((mode (car item)) nodes)
+ (dolist (rule (cdr item)) (push (car rule) nodes))
+ (push (cons mode nodes) alist)))
+ alist)
+ "An alist of (mode . (list of tree-sitter-nodes considered foldable in this
mode)).")
+
(defcustom tree-sitter-fold-mode-hook nil
"Hook to run when enabling `tree-sitter-fold-mode`."
:type 'hook
- [nongnu] elpa/treesit-fold 10cd5dfc38 025/417: Add license, (continued)
- [nongnu] elpa/treesit-fold 10cd5dfc38 025/417: Add license, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ec4c14c7e2 029/417: Add makefile for CI, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a6a1500445 040/417: Add c and c++ support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold bf295cd834 041/417: Add more details, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6bdfc84909 043/417: Add js, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 1abf9923ee 042/417: Add js, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 41b39499aa 047/417: Allow warnings, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6ea9943f9d 048/417: Place CI badge under, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 05d2b87611 056/417: Add offset, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fcd5828d3f 058/417: Update Cask, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 045841504e 059/417: Simplify node alist,
ELPA Syncer <=
- [nongnu] elpa/treesit-fold 17d029c8bd 064/417: Update Cask, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7a2cbb3c80 066/417: Add changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e38981daf7 070/417: Enalbe compile, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold dc670a048b 072/417: Add readme, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a5d413e45c 074/417: Complete Java, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold de128eaf10 076/417: Add CSS, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 23bd9c2c05 077/417: Add CSS, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fef90261f5 082/417: Apply offset, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 76e0dd263e 088/417: Hide indicators when single line, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 8fc88e29f5 089/417: Login update for Csharp comment, ELPA Syncer, 2024/07/01