Subject: bug#77256: Treesit language-at-point

From: Juri Linkov <[email-masked]>
Date: Fri, 04 Apr 2025 19:14:11 +0300

>>> We should also update manual sections that mentions treesit-language-at.
>> 
>> Will do when everything is ok with this patch:
>
> Thanks! LGTM.

Unfortunately, I discovered that it causes treesit-node-outdated errors.

This is because overlays are updated by 'pre-redisplay-functions'
later than outline-minor-mode uses them by 'after-change-functions',
since 'after-change-functions' runs before 'pre-redisplay-functions'.

The reproducible test case: with the latest patch for treesit.el,
and another patch that removes 'mhtml-ts-mode--language-at-point'
from mhtml-ts-mode.el, open a simple html file like this:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
</body>
</html>

then type:

1. M-x load-library RET treesit-x RET
2. M-x liquid-generic-ts-mode RET
3. M-x outline-minor-mode RET
4. move point before </html>
5. type SPC

then with non-nil debug-on-error:

Debugger entered--Lisp error: (treesit-node-outdated #<treesit-node-outdated>)
  treesit-node-enclosed-p(#<treesit-node-outdated> #<treesit-node element in 17-82>)
  treesit-navigate-thing(73 1 beg html-ts-mode--outline-predicate)
  treesit-outline-search(#<marker at 82 in test.html>)
  outline-map-region(#<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_46> 74 82)
  outline--fix-up-all-buttons(74 82)
  outline--fix-buttons-after-change(74 75 0)
  self-insert-command(1 32)
  funcall-interactively(self-insert-command 1 32)
  command-execute(self-insert-command)