[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 999f295bf4 282/417: fix: Don't fold lint comm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 999f295bf4 282/417: fix: Don't fold lint comment when only 1 line (#69) |
Date: |
Mon, 1 Jul 2024 10:02:35 -0400 (EDT) |
branch: elpa/treesit-fold
commit 999f295bf4445a4d3699a335e5e254429d45808e
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>
fix: Don't fold lint comment when only 1 line (#69)
* fix: Don't fold lint comment when only 1 line
* until valid node
---
ts-fold.el | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/ts-fold.el b/ts-fold.el
index 5e2cf91b5c..c2b9d9eb73 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -221,6 +221,15 @@ ts-fold can act on."
;; (@* "Core" )
;;
+(defun ts-fold--get-fold-range (node)
+ "Return the beginning (as buffer position) of fold for NODE.
+Return nil if there is no fold to be made."
+ (when-let* ((fold-alist (alist-get major-mode ts-fold-range-alist))
+ (fold-func (alist-get (tsc-node-type node) fold-alist)))
+ (cond ((functionp fold-func) (funcall fold-func node (cons 0 0)))
+ ((listp fold-func) (funcall (nth 0 fold-func) node (cons (nth 1
fold-func) (nth 2 fold-func))))
+ (t (user-error "Bad folding function for node")))))
+
(defun ts-fold--foldable-node-at-pos (&optional pos)
"Return the smallest foldable node at POS. If POS is nil, use `point'.
@@ -233,19 +242,12 @@ This function is borrowed from
`tree-sitter-node-at-point'."
(node (tsc-get-descendant-for-position-range root pos pos))
;; Used for looping
(current node))
- (while (and current (not (alist-get (tsc-node-type current) mode-ranges)))
+ (while (and current
+ (or (not (alist-get (tsc-node-type current) mode-ranges))
+ (not (ts-fold--get-fold-range current))))
(setq current (tsc-get-parent current)))
current))
-(defun ts-fold--get-fold-range (node)
- "Return the beginning (as buffer position) of fold for NODE.
-Return nil if there is no fold to be made."
- (when-let* ((fold-alist (alist-get major-mode ts-fold-range-alist))
- (fold-func (alist-get (tsc-node-type node) fold-alist)))
- (cond ((functionp fold-func) (funcall fold-func node (cons 0 0)))
- ((listp fold-func) (funcall (nth 0 fold-func) node (cons (nth 1
fold-func) (nth 2 fold-func))))
- (t (user-error "Bad folding function for node")))))
-
;;
;; (@* "Overlays" )
;;
@@ -452,6 +454,7 @@ Argument PREFIX is the comment prefix in string."
(when-let* ((ts-fold-line-comment-mode) ; XXX: Check enabled!?
(first-node (ts-fold--continuous-node-prefix node prefix nil))
(last-node (ts-fold--continuous-node-prefix node prefix t))
+ ((not (equal first-node last-node)))
(prefix-len (length prefix))
(beg (+ (tsc-node-start-position first-node) prefix-len))
(end (tsc-node-end-position last-node)))
- [nongnu] elpa/treesit-fold 7fdaf447cc 245/417: Change global mode to turn on with tree-sitter (#41), (continued)
- [nongnu] elpa/treesit-fold 7fdaf447cc 245/417: Change global mode to turn on with tree-sitter (#41), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 07fe2d17f4 249/417: feature: Add minor-mode for line comment (#45), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 458903e88d 250/417: fix: Fix nil tree-sitter-node, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6ada31e372 251/417: changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fbb5510d5c 290/417: feat: Add LaTex support (#76), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 81dc9eff92 283/417: Update CHANGELOG.md, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f8df121f08 270/417: ci(dependabot): Maintain github-actions, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a474fd6b42 285/417: feat: Add Jai support (#71), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 27e8f44fb6 269/417: test: Emacs 29.1, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7110ff8943 287/417: feat: Add Scheme support (#73), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 999f295bf4 282/417: fix: Don't fold lint comment when only 1 line (#69),
ELPA Syncer <=
- [nongnu] elpa/treesit-fold befad113c9 390/417: feat: Return node when closing, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9d18dee909 354/417: Added a matlab parser for folding., ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold bfdba4f0a8 339/417: fix PR id, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 56c19e3b2d 351/417: chore: Update changelog and README regarding dev, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 37715b54ee 309/417: feat: Add reStructuredText support (#89), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a54a3c92fd 315/417: feat: Add GLSL support (#94), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 1827d0aa9e 319/417: perf: Render indicators in display range (#97), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 0d602a06b1 378/417: Rename ts-fold to treesit-fold, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicators on non foldable node, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold db6cd0ae4f 352/417: style: Ensure spaces, ELPA Syncer, 2024/07/01