Subject: bug#77077: Markers in treesit_check_node

From: Juri Linkov <[email-masked]>
Date: Wed, 19 Mar 2025 09:23:09 +0200

>> treesit_check_position (Lisp_Object obj, struct buffer *buf)
>> {
>> +  if (MARKERP (obj))
>> +    obj = make_fixnum (marker_position (obj));
>> +
>
> We call XFIXNUM (obj) after treesit_check_position in a lot of places. Your
> patch didn’t cause any crash?

No crashes at all.  I guess this is because of automatic conversion of
markers to integers.

> Anyway, I think we should keep treesit_check_position as-is. And
> change treesit-indent-region to convert markers to integers. Integer
> and marker might be interchangeable in Lisp, but I don’t think it’s
> a good idea to mingle them in C.

OK, then let's fix only treesit-indent-region:

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 46332cb1e4b..7410c0f32a8 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2602,6 +2602,8 @@ treesit--indent-region-batch-size
 (defun treesit-indent-region (beg end)
   "Indent the region between BEG and END.
 Similar to `treesit-indent', but indent a region instead."
+  (when (markerp beg) (setq beg (marker-position beg)))
+  (when (markerp end) (setq end (marker-position end)))
   (treesit-update-ranges beg end)
   ;; We indent `treesit--indent-region-batch-size' lines at a time, to
   ;; reduce the number of times the parser needs to re-parse.  In each