Subject: bug#77906: 31.0.50; php-js-mode and js-ts-mode: treesit-show-paren-data--categorize: peculiar error: ("Cannot find the definition of the predicate in `treesit-thing-settings'" list)

From: Juri Linkov <[email-masked]>
Date: Wed, 23 Apr 2025 19:55:34 +0300

> Now added this docstring to the internal function
> 'treesit-show-paren-data--categorize':
>
>     "Return a list suitable for `show-paren-data-function' (which see).
>   If the optional argument END-P is non-nil, interpret the position POS
>   as belonging to the node that ends before POS (by subtracting 1 from POS)."
>
> I guess more functions will need such flag, e.g. 'backward-sexp'
> at the end of the range doesn't skip to the embedded node's start.

This patch is not for immediate installation, but
it demonstrates how this problem can be fixed:

  diff --git a/lisp/treesit.el b/lisp/treesit.el
  index bf5c1ed5f6c..c73b380f38c 100644
  --- a/lisp/treesit.el
  +++ b/lisp/treesit.el
  @@ -869,7 +869,7 @@ treesit-parsers-at
     (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 (1- (or pos (point)))))
         (when-let* ((parser (overlay-get ov 'treesit-parser))
                     (host-parser (or (null with-host)
                                      (overlay-get ov 'treesit-host-parser)))

With this patch the following case works correctly in test.heex:

  <%= if true do %>
    <p>hello, tree-sitter!</p>
  <% end| %>

With point at "|" the command 'backward-sexp' (C-M-b)
correctly jumps to the beginning of "if".