[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 68c7954b3a 155/417: Apply more accurate c-lik
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 68c7954b3a 155/417: Apply more accurate c-like comment |
Date: |
Mon, 1 Jul 2024 10:02:21 -0400 (EDT) |
branch: elpa/treesit-fold
commit 68c7954b3a9b3afac30623022c504cc15d22d1ec
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>
Apply more accurate c-like comment
---
tree-sitter-fold.el | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/tree-sitter-fold.el b/tree-sitter-fold.el
index a760bf9678..86baad465b 100644
--- a/tree-sitter-fold.el
+++ b/tree-sitter-fold.el
@@ -41,6 +41,7 @@
(require 'seq)
(require 'subr-x)
+(require 's)
(require 'tree-sitter)
(require 'tree-sitter-fold-util)
@@ -333,10 +334,6 @@ If the current syntax node is not foldable, do nothing."
;; (@* "Rule Helpers" )
;;
-(defun tree-sitter-fold--multi-line (node)
- "Return t, if content NODE is single line."
- (string-match-p "\n" (tsc-node-text node)))
-
(defun tree-sitter-fold--next-prev-node (node next)
"Return previous/next sibling node starting from NODE.
@@ -349,14 +346,18 @@ then return the last iterated node.
Argument NEXT is a boolean type. If non-nil iterate forward; otherwise iterate
in backward direction."
- (let ((iter-node (tree-sitter-fold--next-prev-node node next)) (last-node
node)
- (last-line (car (tsc-node-start-point node))) line text break)
+ (let ((iter-node node) (last-node node)
+ (last-line (car (tsc-node-start-point node))) line text break
+ (line-range 1) (last-line-range 1) max-line-range)
(while (and iter-node (not break))
(setq text (tsc-node-text iter-node)
- line (car (tsc-node-start-point iter-node)))
- (if (and (tree-sitter-fold-util--in-range-p line (1- last-line) (1+
last-line))
+ line (car (tsc-node-start-point iter-node))
+ line-range (1+ (s-count-matches "\n" text))
+ max-line-range (max line-range last-line-range))
+ (if (and (tree-sitter-fold-util--in-range-p line (- last-line
max-line-range) (+ last-line max-line-range))
(string-prefix-p prefix text))
- (setq last-node iter-node last-line line)
+ (setq last-node iter-node last-line line
+ last-line-range (1+ (s-count-matches "\n" text)))
(setq break t))
(setq iter-node (tree-sitter-fold--next-prev-node iter-node next)))
last-node))
@@ -392,11 +393,12 @@ more information."
(defun tree-sitter-fold-range-c-like-comment (node offset)
"Define fold range for C-like comemnt."
- (if (tree-sitter-fold--multi-line node)
- (tree-sitter-fold-range-block-comment node offset)
- (if (string-prefix-p "///" (tsc-node-text node))
- (tree-sitter-fold-range-line-comment node offset "///")
- (tree-sitter-fold-range-line-comment node offset "//"))))
+ (let ((text (tsc-node-text node)))
+ (if (and (string-match-p "\n" text) (string-prefix-p "/*" text))
+ (tree-sitter-fold-range-block-comment node offset)
+ (if (string-prefix-p "///" text)
+ (tree-sitter-fold-range-line-comment node offset "///")
+ (tree-sitter-fold-range-line-comment node offset "//")))))
;;
;; (@* "Languages" )
- [nongnu] elpa/treesit-fold 41c13ff0e2 416/417: 2 bug fix (#10), (continued)
- [nongnu] elpa/treesit-fold 41c13ff0e2 416/417: 2 bug fix (#10), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold eb714e2c21 408/417: feat: Add Gleam support (#8), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 14e3f13f67 415/417: feat: Enhance the Gleam support (#9), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7833eb31ab 096/417: Function void, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ad0e036355 099/417: Core, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 862b571191 118/417: Remove def, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 44714c252a 126/417: Quote description, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a1b5e97fa0 132/417: Improve doc, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 49aff53680 136/417: Add comment, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 5e956f74dc 148/417: Support python comment and document string, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 68c7954b3a 155/417: Apply more accurate c-like comment,
ELPA Syncer <=
- [nongnu] elpa/treesit-fold b2222f0f7f 159/417: Update list, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 68d16a9bc9 166/417: Rename to ts-fold, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d556beb204 172/417: Merge pull request #4 from rynffoll/feature/add-support-evil-toggle-fold, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 52d36972ef 218/417: chore(list): sort language alphabetically (#12), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ea554f10e7 220/417: Fix a minor typo in ts-fold-parsers.el (#14), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a7c29941c2 225/417: OCaml parser and first functions added (#21), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 1d690b8d06 267/417: feat(python): Support assignment string, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 78f0b0437f 278/417: docs(README.md): Mention Noir in TODO, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold c36f3ad85c 279/417: feat: Add Perl support (#66), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold be2b3dd211 275/417: feat: Add Elisp support (#63), ELPA Syncer, 2024/07/01