Subject: Re: bug#68993: treesitter support for forward-sexp-default-function

From: Juri Linkov <[email-masked]>
Date: Mon, 12 Feb 2024 20:41:46 +0200

>> The problem is that e.g. Ruby parser to such text:
>>
>>  hash[:key]
>>
>> produces such syntax tree:
>>
>>  (element_reference object: (identifier) [ (simple_symbol) ])
>>
>> so when point is on [ then 'C-M-f' can't move to ].
>>
>> This is fixed now by the third patch:
>> @@ -1170,7 +1170,20 @@ ruby-ts-mode
>> +                 (comment ,(lambda (node)
>> +                             (or (member (treesit-node-type node)
>> +                                         '("comment" "string_content"))
>> +                                 (and (member (treesit-node-text node)
>> +                                              '("[" "]"))
>> +                                      (equal (treesit-node-type
>> +                                              (treesit-node-parent node))
>> +                                             "element_reference"))
>> +                                 (and (member (treesit-node-text node)
>> +                                              '("#{" "}"))
>> +                                      (equal (treesit-node-type
>> +                                              (treesit-node-parent node))
>> +                                             "interpolation"))))))))
>
> IIUC, this doesn’t look like a good idea: you don’t want to mark
> something that’s not comment as comment. In the future, other packages
> will start using these thing definitions, and I’m sure you don’t want
> them consider regular code as comments.
>
> For the specific problem you described, maybe the change made in #68899 can help?

bug#68899 can't help because it only fixes 'C-M-f' to move point to the
end of the current symbol.

Whereas for the problem above we need a predicate that will instruct
'treesit-forward-sexp' to fall back to 'forward-sexp-default-function'.

Clearly neither the name 'text' nor 'comment' would be suitable
for such usage.  Maybe it's possible to find a different name?