GNU bug report logs - #60256
29.0.60; Maybe improve tree sitter default treesit-language-at function

Previous Next

Package: emacs;

Reported by: Wilhelm H Kirschbaum <wilhelm <at> floatpays.co.za>

Date: Thu, 22 Dec 2022 10:35:02 UTC

Severity: normal

Tags: wontfix

Found in version 29.0.60

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Wilhelm H Kirschbaum <wilhelm <at> floatpays.co.za>
Subject: bug#60256: closed (Re: bug#60256: 29.0.60; Maybe improve tree
 sitter default treesit-language-at function)
Date: Sat, 02 Sep 2023 16:42:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 60256 <at> debbugs.gnu.org.

-- 
60256: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60256
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Yuan Fu <casouri <at> gmail.com>, 60256-done <at> debbugs.gnu.org,
 wilhelm <at> floatpays.co.za
Subject: Re: bug#60256: 29.0.60; Maybe improve tree sitter default
 treesit-language-at function
Date: Sat, 2 Sep 2023 09:41:05 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

> tags 60256 wontfix
> thanks
>
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Sat, 24 Dec 2022 14:43:18 -0800
>> Cc: Wilhelm Hugo Kirschbaum <wilhelm <at> floatpays.co.za>,
>>  60256 <at> debbugs.gnu.org
>>
>>
>> Yeah, sorry for the delay. I don’t think it’s worth it, because (1) I
>> expect major modes with multiple langauges to implement
>> treesit-language-at-point-function which takes care of all the work, and
>> (2) in the rare case where there are multiple languages and no
>> treesit-language-at-point-function, using the first language whose range
>> spans point (this patch) is not necessarily correct: the host language (eg, HTML
>> among HTML, CSS & JavaScript) always covers the whole buffer, only
>> embedded languages has ranges.
>
> OK, thanks.

I'm therefore closing this bug report.

[Message part 3 (message/rfc822, inline)]
From: Wilhelm H Kirschbaum <wilhelm <at> floatpays.co.za>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.60; Maybe improve tree sitter default treesit-language-at
 function
Date: Thu, 22 Dec 2022 12:30:09 +0200
We can detect the language from treesit-parser-included-ranges, so
instead of taking the first parser from the list what about taking 
the
first parser within known ranges?

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 6407669118..f08bb1cd40 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -136,8 +136,20 @@ treesit-language-at
parser in `treesit-parser-list', or nil if there is no parser."
  (if treesit-language-at-point-function
      (funcall treesit-language-at-point-function position)
-    (when-let ((parser (car (treesit-parser-list))))
-      (treesit-parser-language parser))))
+    (let ((language-in-range
+         (cl-loop
+          for parser in (treesit-parser-list)
+          do (setq range
+                   (cl-loop
+                    for range in (treesit-parser-included-ranges 
parser)
+                    if (and (>= point (car range)) (<= point (cdr 
range)))
+                    return parser))
+          if range
+          return (treesit-parser-language parser))))
+    (if (null language-in-range)
+        (when-let ((parser (car (treesit-parser-list))))
+          (treesit-parser-language parser))
+      language-in-range))))


Maybe there is a better way of doing this, but seems like it can 
be
generic enough to make this work without having to set
treesit-language-at-point-function for the majority of the cases.

Wilhelm



This bug report was last modified 1 year and 260 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.