From: Juri Linkov Date: Mon, 12 May 2025 18:23:03 +0000 (+0300) Subject: * lisp/treesit.el (treesit--parser-overlay-offset): New variable. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2c5f8dd44e0f6f40d2a4f590e12f2a3235048e6a;p=emacs.git * lisp/treesit.el (treesit--parser-overlay-offset): New variable. (treesit-parsers-at): Use it (bug#77906). (treesit-forward-sexp, treesit--forward-list-with-default) (treesit-up-list): Let-bind 'treesit--parser-overlay-offset'. (cherry picked from commit 824e4868db312f0cd9e735cf13d54466c4af5934) --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 9cbf063be1d..c2dc9ab4602 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -838,6 +838,11 @@ those inside are kept." if (<= start (car range) (cdr range) end) collect range)) +(defvar treesit--parser-overlay-offset 0 + "Defines at which position to get the parser overlay. +The commands that move backward need to set it to -1 to be +able to use the range that ends immediately before point.") + (defun treesit-parsers-at (&optional pos language with-host only) "Return all parsers at POS. @@ -868,7 +873,8 @@ That is, the deepest embedded parser comes first." (let ((res nil)) ;; Refer to (ref:local-parser-overlay) for more explanation of local ;; parser overlays. - (dolist (ov (overlays-at (or pos (point)))) + (dolist (ov (overlays-at (+ (or pos (point)) + treesit--parser-overlay-offset))) (when-let* ((parser (overlay-get ov 'treesit-parser)) (host-parser (or (null with-host) (overlay-get ov 'treesit-host-parser))) @@ -3011,7 +3017,8 @@ across atoms (such as symbols or words) inside the list." t) (if (> arg 0) (treesit-end-of-thing pred (abs arg) 'restricted) - (treesit-beginning-of-thing pred (abs arg) 'restricted)) + (let ((treesit--parser-overlay-offset -1)) + (treesit-beginning-of-thing pred (abs arg) 'restricted))) ;; If we couldn't move, we should signal an error and report ;; the obstacle, like `forward-sexp' does. If we couldn't ;; find a parent, we simply return nil without moving point, @@ -3026,6 +3033,7 @@ the boundaries of the list. ARG is described in the docstring of `forward-list'." (let* ((pred (or treesit-sexp-type-regexp 'list)) (arg (or arg 1)) + (treesit--parser-overlay-offset (if (> arg 0) 0 -1)) (cnt arg) (inc (if (> arg 0) 1 -1))) (while (/= cnt 0) @@ -3153,6 +3161,7 @@ ARG is described in the docstring of `up-list'." (interactive "^p") (let* ((pred (or treesit-sexp-type-regexp 'list)) (arg (or arg 1)) + (treesit--parser-overlay-offset -1) (cnt arg) (inc (if (> arg 0) 1 -1))) (while (/= cnt 0)