emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]