GNU bug report logs - #77256
Treesit language-at-point

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 25 Mar 2025 18:44:02 UTC

Severity: normal

Fixed in version 31.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo <at> gmail.com>, Juri Linkov <juri <at> linkov.net>
Subject: bug#77256: Treesit language-at-point
Date: Tue, 15 Apr 2025 16:28:53 -0700

> On Apr 10, 2025, at 7:47 AM, Stefan Monnier <monnier <at> iro.umontreal.ca> 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



This bug report was last modified 91 days ago.

Previous Next


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