Subject: bug#75198: 31.0.50; [treesitter] peculiar error

From: Yuan Fu <[email-masked]>
Date: Sat, 4 Jan 2025 11:22:54 -0800

> On Jan 4, 2025, at 9:43 AM, Juri Linkov <[email-masked]> wrote:
> 
>>> The problem is that 'treesit-parent-until' raises an error by default.
>>> So needed to copy its implementation where treesit-node-match-p
>>> sets the argument IGNORE-MISSING to t.
>>> 
>>> Or maybe better to add new arg IGNORE-MISSING to treesit-parent-until.
>> 
>> Hmm, I’m not sure. If we go this route, we’d need to add IGNORE-MISSING for
>> every single function that uses treesit-node-match-p.
> 
> Agreed, adding a new arg to all such functions is not the right thing.
> 
> Then maybe better to define the preferred behavior
> by a new dynamically bound variable, e.g.
> (let ((treesit-raise-error t)) (treesit-parent-until ... pred))
> 
>> It’s better for these functions to check whether the definition of the
>> thing they’re going to use exists or not, before calling
>> treesit-node-match-p; alternatively, if they know they don’t care,
>> they can pass t to IGNORE-MISSING.
> 
> Not sure how much this will degrade the performance of
> every function that uses treesit-node-match-p.

It should be negligible, plus if a function wants to use a thing, it’s TRT to first check if the thing exists, right? Otherwise they can just pass IGNORE-MISSING.

There might be cases where the function can’t know whether they can ignore missing. In that case they can expose the IGNORE-MISSING parameter in their signature.

Treesit-raise-error-p could make sense, but it’s a rather significant commitment and I don’t see any strong argument for it as for now. 

Yuan