]> git.eshelyaron.com Git - emacs.git/commitdiff
More consistent treesit-forward-sexp around comments (bug#72525)
authorYuan Fu <casouri@gmail.com>
Tue, 27 Aug 2024 02:43:00 +0000 (19:43 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 4 Sep 2024 07:51:38 +0000 (09:51 +0200)
* lisp/treesit.el (treesit-forward-sexp): Check if point is strictly
inside a comment or string, only then use the default forward-sexp
function; otherwise use tree-sitter's forward-sexp routine.

(cherry picked from commit 3a4839d142757ce6fabe81473e337acd13f51826)

lisp/treesit.el

index 6112adde0913ff37a5035af4123c0300fba9c994..2d52edb306a42b2bbd062530ea0f219132b733e0 100644 (file)
@@ -2239,8 +2239,15 @@ What constitutes as text and source code sexp is determined
 by `text' and `sexp' in `treesit-thing-settings'."
   (interactive "^p")
   (let ((arg (or arg 1))
-        (pred (or treesit-sexp-type-regexp 'sexp)))
-    (or (when (treesit-node-match-p (treesit-node-at (point)) 'text t)
+        (pred (or treesit-sexp-type-regexp 'sexp))
+        (node-at-point
+         (treesit-node-at (point) (treesit-language-at (point)))))
+    (or (when (and node-at-point
+                   ;; Make sure point is strictly inside node.
+                   (< (treesit-node-start node-at-point)
+                      (point)
+                      (treesit-node-end node-at-point))
+                   (treesit-node-match-p node-at-point 'text t))
           (forward-sexp-default-function arg)
           t)
         (if (> arg 0)