[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicat
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 342eb5ee1f 324/417: fix: Don't render indicators on non foldable node |
Date: |
Mon, 1 Jul 2024 10:02:59 -0400 (EDT) |
branch: elpa/treesit-fold
commit 342eb5ee1f242ac03bc7e7bbe8d67be8711423ae
Author: JenChieh <jcs090218@gmail.com>
Commit: JenChieh <jcs090218@gmail.com>
fix: Don't render indicators on non foldable node
---
ts-fold-indicators.el | 9 ++++--
ts-fold.el | 76 +++++++++++++++++++++++----------------------------
2 files changed, 41 insertions(+), 44 deletions(-)
diff --git a/ts-fold-indicators.el b/ts-fold-indicators.el
index 4eeed1a650..5956ff47b6 100644
--- a/ts-fold-indicators.el
+++ b/ts-fold-indicators.el
@@ -283,7 +283,7 @@ Argument FOLDED holds folding state; it's a boolean."
(ts-fold-indicators--create-overlays beg end folded))))
(defun ts-fold-indicators--size-change (&optional frame &rest _)
- "Render indicators for all visible windows."
+ "Render indicators for all visible windows from FRAME."
(ts-fold--with-no-redisplay
(dolist (win (window-list frame)) (ts-fold-indicators--render-window
win))))
@@ -320,7 +320,12 @@ Argument FOLDED holds folding state; it's a boolean."
(nodes-to-fold
(cl-remove-if-not (lambda (node)
(ts-fold--within-window (cdr node) wend
wstart))
- nodes-to-fold)))
+ nodes-to-fold))
+ (mode-ranges (alist-get major-mode ts-fold-range-alist))
+ (nodes-to-fold
+ (cl-remove-if (lambda (node)
+ (ts-fold--non-foldable-node-p (cdr node)
mode-ranges))
+ nodes-to-fold)))
(ts-fold-indicators--remove-ovs)
(thread-last nodes-to-fold
(mapcar #'cdr)
diff --git a/ts-fold.el b/ts-fold.el
index e1527e7565..e5b31a4351 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -274,8 +274,8 @@ Return nil if there is no fold to be made."
((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-p (node mode-ranges)
- "Return non-nil if NODE is foldable in MODE-RANGES."
+(defun ts-fold--non-foldable-node-p (node mode-ranges)
+ "Return non-nil if NODE is a non-foldable in MODE-RANGES."
(or (not (alist-get (tsc-node-type node) mode-ranges)) ; Not registered,
continue.
(let ((range (ts-fold--get-fold-range node)))
(or (not range) ; Range not defined,
continue.
@@ -294,7 +294,7 @@ This function is borrowed from `tree-sitter-node-at-point'."
;; Used for looping
(current node))
(while (and current
- (ts-fold--foldable-node-p current mode-ranges))
+ (ts-fold--non-foldable-node-p current mode-ranges))
(setq current (tsc-get-parent current)))
current))
@@ -474,10 +474,6 @@ in backward direction."
(setq iter-node (ts-fold--next-prev-node-skip-newline iter-node next)))
last-node))
-(defun ts-fold--one-liner-node (node)
- "Helper function to check if NODE is on one line only."
- (= (car (aref (tsc-node-range node) 2)) (car (aref (tsc-node-range node)
3))))
-
(defun ts-fold-range-seq (node offset)
"Return the fold range in sequence starting from NODE.
@@ -893,59 +889,55 @@ more information."
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
- (unless (ts-fold--one-liner-node node)
- (when-let* ((text (tsc-node-text node))
- (beg (+ (if (string-prefix-p "(* " text) 2 3)
- (tsc-node-start-position node)))
- (end (- (tsc-node-end-position node) 2)))
- (ts-fold--cons-add (cons beg end) offset))))
+ (when-let* ((text (tsc-node-text node))
+ (beg (+ (if (string-prefix-p "(* " text) 2 3)
+ (tsc-node-start-position node)))
+ (end (- (tsc-node-end-position node) 2)))
+ (ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-ocaml-module-definition (node offset)
"Define fold range for `module_definition'.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
- (unless (ts-fold--one-liner-node node)
- (when-let*
- ((module-binding (tsc-get-nth-named-child node 0))
- (body (tsc-get-child-by-field module-binding :body))
- ;; body is struct ... end
- (beg (+ 6 (tsc-node-start-position body)))
- (end (- (tsc-node-end-position node) 3)))
- (ts-fold--cons-add (cons beg end) offset))))
+ (when-let*
+ ((module-binding (tsc-get-nth-named-child node 0))
+ (body (tsc-get-child-by-field module-binding :body))
+ ;; body is struct ... end
+ (beg (+ 6 (tsc-node-start-position body)))
+ (end (- (tsc-node-end-position node) 3)))
+ (ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-ocaml-type-definition (node offset)
"Define fold range for `type_definition'.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
- (unless (ts-fold--one-liner-node node)
- (when-let*
- ((type-definition (tsc-get-nth-named-child node 0))
- (body (tsc-get-child-by-field type-definition :body))
- (text (tsc-node-text (tsc-get-nth-child body 0)))
- (beg
- (if (string-equal "{" text)
- (1+ (tsc-node-start-position body))
- (tsc-node-end-position (tsc-get-prev-sibling body))))
- (end
- (if (string-equal "{" text)
- (1- (tsc-node-end-position node))
- (tsc-node-end-position node))))
- (ts-fold--cons-add (cons beg end) offset))))
+ (when-let*
+ ((type-definition (tsc-get-nth-named-child node 0))
+ (body (tsc-get-child-by-field type-definition :body))
+ (text (tsc-node-text (tsc-get-nth-child body 0)))
+ (beg
+ (if (string-equal "{" text)
+ (1+ (tsc-node-start-position body))
+ (tsc-node-end-position (tsc-get-prev-sibling body))))
+ (end
+ (if (string-equal "{" text)
+ (1- (tsc-node-end-position node))
+ (tsc-node-end-position node))))
+ (ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-ocaml-value-definition (node offset)
"Define fold range for `value_definition'.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
- (unless (ts-fold--one-liner-node node)
- (when-let*
- ((let-binding (tsc-get-nth-named-child node 0))
- (body (tsc-get-child-by-field let-binding :body))
- (beg (tsc-node-end-position (tsc-get-prev-sibling body)))
- (end (tsc-node-end-position node)))
- (ts-fold--cons-add (cons beg end) offset))))
+ (when-let*
+ ((let-binding (tsc-get-nth-named-child node 0))
+ (body (tsc-get-child-by-field let-binding :body))
+ (beg (tsc-node-end-position (tsc-get-prev-sibling body)))
+ (end (tsc-node-end-position node)))
+ (ts-fold--cons-add (cons beg end) offset)))
;;- OCaml
- [nongnu] elpa/treesit-fold 7110ff8943 287/417: feat: Add Scheme support (#73), (continued)
- [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, 2024/07/01
- [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 <=
- [nongnu] elpa/treesit-fold db6cd0ae4f 352/417: style: Ensure spaces, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 4b35e27148 311/417: feat: Add SQL support (#91), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d1b07c7bb0 320/417: Update CHANGELOG.md, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d8a4bb568b 392/417: feat: Ensure indicators is refreshed after show/hide, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 11913082da 377/417: Ignore ds_store, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 731adc1607 362/417: fix(asm): Enhance assembly comment's folding, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 545ec26be1 412/417: docs: Add Vimscript to supported list, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 675e5e732c 414/417: fix: Allow error in continuous node, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 380ccb0d77 092/417: Remove macro, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e25ece59b5 114/417: Add rust macro support, ELPA Syncer, 2024/07/01