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

From: Yuan Fu <[email-masked]>
Date: Tue, 15 Apr 2025 16:28:53 -0700

> On Apr 10, 2025, at 7:47 AM, Stefan Monnier <[email-masked]> wrote:
> 
>>>> Is it?
>>>> I can't find any code out there that seems to care what is its default
>>>> value (all users set it but doesn't look at it, AFAICT).
>> The default value shouldn't matter.  What’s the difference between
>> a major-mode-set non-nil value and a default non-nil value?
> 
> No difference, in theory, indeed.
> The problem is when code cares about the nil -vs- non-nil value of the variable.
> 
>>> This case looks problematic:
>>> 
>>>                ;; LANG can be nil.  We don't want to use the fallback
>>>                ;; in `treesit-language-at', so here we call
>>>                ;; `treesit-language-at-point-function' directly.
>>>                (let* ((lang (and treesit-language-at-point-function
>>>                                  (funcall treesit-language-at-point-function
>>>                                           pos)))
>>> 
>>> But I believe this whole 'let*' can be replaced by just
>>> the 'treesit-parsers-at' call.  I hope Yuan could confirm this.
>> 
>> Why is this problematic?
> 
> Because the `and` treats `treesit-language-at-point-function` as
> a boolean rather than as a function (and according to the comment, it
> does so to avoid the default behavior, so if we set the var to a non-nil
> value that provides the default behavior, it defeats the purpose of the
> test).

Oops, that was bad code on my part—it wasn’t intentional. 

> 
> But apparently, Juri's patch gets rid of this problem.  🙂

Yeah, feel free to apply the patch, Juri :)

Yuan