Subject: bug#77077: Markers in treesit_check_node

From: Juri Linkov <[email-masked]>
Date: Mon, 17 Mar 2025 19:52:27 +0200

In mhtml-ts-mode activate the region, type 'C-c C-t'
and an element name like div, type RET RET, then:

Debugger entered--Lisp error: (wrong-type-argument integerp #<marker (moves after insertion) at 10 in test.html>)
  treesit-query-capture(#<treesit-parser for html> #<treesit-compiled-query> 7 #<marker (moves after insertion) at 10 in test.html>)
  treesit-query-range(#<treesit-parser for html> #<treesit-compiled-query> 7 #<marker (moves after insertion) at 10 in test.html> nil nil)
  treesit--update-ranges-non-local(#<treesit-parser for html> #<treesit-compiled-query> javascript 32 1 7 #<marker (moves after insertion) at 10 in test.html> nil nil)
  treesit--update-range-1(7 #<marker (moves after insertion) at 10 in test.html> #<treesit-parser for html> ...)
  treesit-update-ranges(7 #<marker (moves after insertion) at 10 in test.html>)
  treesit-indent-region(7 #<marker (moves after insertion) at 10 in test.html>)
  indent-region(7 #<marker (moves after insertion) at 10 in test.html> nil)
  skeleton-internal-1(n t nil)
  skeleton-insert(... -1 nil)
  skeleton-proxy-new(... nil nil)
  sgml-tag(nil nil)
  funcall-interactively(sgml-tag nil nil)
  command-execute(sgml-tag)

Here's the patch to fix this and it seems no more changes necessary
since it fails only on checking, but on using it converts markers
to numbers automatically.

diff --git a/src/treesit.c b/src/treesit.c
index b0979397d35..7df9bb4d0d3 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2190,6 +2190,9 @@ treesit_check_node (Lisp_Object obj)
 static void
 treesit_check_position (Lisp_Object obj, struct buffer *buf)
 {
+  if (MARKERP (obj))
+    obj = make_fixnum (marker_position (obj));
+
   treesit_check_positive_integer (obj);
   ptrdiff_t pos = XFIXNUM (obj);
   if (pos < BUF_BEGV (buf) || pos > BUF_ZV (buf))