* bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function
@ 2022-12-22 10:30 Wilhelm H Kirschbaum
2022-12-24 7:25 ` Eli Zaretskii
2022-12-24 22:43 ` Yuan Fu
0 siblings, 2 replies; 5+ messages in thread
From: Wilhelm H Kirschbaum @ 2022-12-22 10:30 UTC (permalink / raw)
To: 60256
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function
2022-12-22 10:30 bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function Wilhelm H Kirschbaum
@ 2022-12-24 7:25 ` Eli Zaretskii
2022-12-24 22:43 ` Yuan Fu
1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2022-12-24 7:25 UTC (permalink / raw)
To: Wilhelm H Kirschbaum, Yuan Fu; +Cc: 60256
> From: Wilhelm H Kirschbaum <wilhelm@floatpays.co.za>
> 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?
Yuan, any comments?
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function
2022-12-22 10:30 bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function Wilhelm H Kirschbaum
2022-12-24 7:25 ` Eli Zaretskii
@ 2022-12-24 22:43 ` Yuan Fu
2022-12-25 6:40 ` Eli Zaretskii
1 sibling, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2022-12-24 22:43 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 60256, Wilhelm Hugo Kirschbaum
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Wilhelm H Kirschbaum <wilhelm@floatpays.co.za>
>> 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?
>
> Yuan, any comments?
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.
Yuan
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function
2022-12-24 22:43 ` Yuan Fu
@ 2022-12-25 6:40 ` Eli Zaretskii
2023-09-02 16:41 ` Stefan Kangas
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-12-25 6:40 UTC (permalink / raw)
To: Yuan Fu; +Cc: 60256, wilhelm
tags 60256 wontfix
thanks
> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 24 Dec 2022 14:43:18 -0800
> Cc: Wilhelm Hugo Kirschbaum <wilhelm@floatpays.co.za>,
> 60256@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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function
2022-12-25 6:40 ` Eli Zaretskii
@ 2023-09-02 16:41 ` Stefan Kangas
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Kangas @ 2023-09-02 16:41 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Yuan Fu, 60256-done, wilhelm
Eli Zaretskii <eliz@gnu.org> writes:
> tags 60256 wontfix
> thanks
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 24 Dec 2022 14:43:18 -0800
>> Cc: Wilhelm Hugo Kirschbaum <wilhelm@floatpays.co.za>,
>> 60256@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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-02 16:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-22 10:30 bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function Wilhelm H Kirschbaum
2022-12-24 7:25 ` Eli Zaretskii
2022-12-24 22:43 ` Yuan Fu
2022-12-25 6:40 ` Eli Zaretskii
2023-09-02 16:41 ` Stefan Kangas
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.