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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/treesit-fold eeb9c03bcc 127/417: Fix conitouse line


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold eeb9c03bcc 127/417: Fix conitouse line
Date: Mon, 1 Jul 2024 10:02:18 -0400 (EDT)

branch: elpa/treesit-fold
commit eeb9c03bcc8583457d8a7cc5370c18b638c28df1
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>

    Fix conitouse line
---
 tree-sitter-fold-util.el |  8 ++++++++
 tree-sitter-fold.el      | 31 ++++++++++++++++++++-----------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/tree-sitter-fold-util.el b/tree-sitter-fold-util.el
index 5caad71688..8873c13b06 100644
--- a/tree-sitter-fold-util.el
+++ b/tree-sitter-fold-util.el
@@ -78,5 +78,13 @@ Optional argument TRIM, see function 
`tree-sitter-fold-util--get-face'."
 Optional argument TRIM, see function `tree-sitter-fold-util--get-face'."
   (tree-sitter-fold-util--is-face obj tree-sitter-fold-util--doc-faces trim))
 
+;;
+;; (@* "Math" )
+;;
+
+(defun tree-sitter-fold-util--in-range-p (in-val in-min in-max)
+  "Check to see if IN-VAL is between IN-MIN and IN-MAX."
+  (and (<= in-min in-val) (<= in-val in-max)))
+
 (provide 'tree-sitter-fold-util)
 ;;; tree-sitter-fold-util.el ends here
diff --git a/tree-sitter-fold.el b/tree-sitter-fold.el
index 264c1a6703..3012c1f47d 100644
--- a/tree-sitter-fold.el
+++ b/tree-sitter-fold.el
@@ -350,12 +350,14 @@ 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)) text break
-        (last-node node))
+  (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)
     (while (and iter-node (not break))
-      (setq text (tsc-node-text iter-node))
-      (if (string-prefix-p prefix text)
-          (setq last-node iter-node)
+      (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))
+               (string-prefix-p prefix text))
+          (setq last-node iter-node last-line line)
         (setq break t))
       (setq iter-node (tree-sitter-fold--next-prev-node iter-node next)))
     last-node))
@@ -427,9 +429,11 @@ more information."
 
 (defun tree-sitter-fold-range-c-preproc-else (node offset)
   "Define fold range for `else' preprocessor."
-  (when-let* ((beg (+ (tsc-node-start-position node) 5))
+  (when-let* ((target "#else")
+              (len (length target))
+              (beg (+ (tsc-node-start-position node) len))
               (text (tsc-node-text node))
-              (end (+ beg (length text) -5)))
+              (end (+ beg (length text) (- 0 len))))
     (tree-sitter-fold-util--cons-add (cons beg end) offset)))
 
 (defun tree-sitter-fold-range-python (node offset)
@@ -446,13 +450,18 @@ more information."
               (end (tsc-node-end-position node)))
     (tree-sitter-fold-util--cons-add (cons beg end) offset)))
 
-(defun tree-sitter-fold-range-ruby (_node _offset)
-  "Define fold range for Ruby.
+(defun tree-sitter-fold-range-ruby-method (node offset)
+  "Define fold range for `method' in Ruby.
 
 For arguments NODE and OFFSET, see function `tree-sitter-fold-range-seq' for
 more information."
-  ;; TODO: ..
-  (progn ))
+  (let* ((named-node (tsc-get-child-by-field node :name))
+         (parameters-node (tsc-get-child-by-field node :parameters))
+         (end-node (tsc-get-child-by-field node :end))
+         (beg (tsc-node-end-position parameters-node))
+         (end 0))
+    (jcs-print ">" end-node)
+    (tree-sitter-fold-util--cons-add (cons beg end) offset)))
 
 (defun tree-sitter-fold-range-rust-macro (node offset)
   "Return the fold range for `macro_definition' NODE in Rust.



reply via email to

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