Skip to content

Commit

Permalink
feat: Add EditorConfig support
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Nov 20, 2024
1 parent e2d6e15 commit dbaf50d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions treesit-fold-parsers.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions treesit-fold-summary.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions treesit-fold.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit dbaf50d

Please sign in to comment.