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

From: Stefan Monnier <[email-masked]>
Date: Thu, 10 Apr 2025 10:47:50 -0400

>>> 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).

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

        Stefan