From 3a4839d142757ce6fabe81473e337acd13f51826 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Mon, 26 Aug 2024 19:43:00 -0700 Subject: [PATCH] More consistent treesit-forward-sexp around comments (bug#72525) * 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. --- lisp/treesit.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 0b0a04af118..3ac8575aad4 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -2254,8 +2254,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)