branch: elpa/treesit-fold
commit 206d849f723faff830ed74a75957cde8ee6252ab
Author: Junyi Hou <[email protected]>
Commit: Junyi Hou <[email protected]>
add support for nix
---
readme.org | 1 +
tree-sitter-fold.el | 12 ++++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/readme.org b/readme.org
index f55d4e4e48..0362522208 100644
--- a/readme.org
+++ b/readme.org
@@ -48,6 +48,7 @@ This variable determines how ~tree-sitter-fold~ should fold
each of the nodes de
- python
- R (need to compile [[https://github.com/r-lib/tree-sitter-r][tree-sitter-r]]
grammar, see [[Note on installing additional grammars]])
+- Nix (need to compile
[[https://github.com/cstrahan/tree-sitter-nix][tree-sitter-nix]], see [[Note no
installing additional grammars]])
- contribution of other languages are welcome!
* Contribution
diff --git a/tree-sitter-fold.el b/tree-sitter-fold.el
index 44fcf51556..91d065f5d8 100644
--- a/tree-sitter-fold.el
+++ b/tree-sitter-fold.el
@@ -31,7 +31,8 @@
(defcustom tree-sitter-fold-foldable-node-alist
'((python-mode . (function_definition class_definition))
- (ess-r-mode . (brace_list)))
+ (ess-r-mode . (brace_list))
+ (nix-mode . (attrset function)))
"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)
@@ -45,7 +46,7 @@
FUNCTION is used to determine where the beginning and end for
FOLDABLE-NODE-TYPE
in MAJOR-MODE. It should take a single argument (the syntax node with type
FOLDABLE-NODE-TYPE) and return the buffer positions of the beginning and end of
-the fold in a cons cell. See `tree-sitter-fold-range-python' for an example."
+the fold in a cons cell. See `tree-sitter-fold-range-python' for an example."
:type '(alist :key-type symbol
:value-type (alist :key-type symbol :value-type function))
:group 'tree-sitter-fold)
@@ -238,6 +239,13 @@ If the current syntax node is not foldable, do nothing."
(end (1- (tsc-node-end-position node))))
(cons beg end)))
+(defun tree-sitter-fold-range-nix (node)
+ "Return the fold range for `attrset' NODE in Nix express language."
+ (let ((beg (tsc-node-end-position (tsc-get-nth-child node 0)))
+ (end (1- (tsc-node-end-position node))))
+ (cons beg end)))
+
+
(provide 'tree-sitter-fold)
;;; tree-sitter-fold.el ends here