Subject: Re: bug#72388: 31.0.50; Use tree-sitter-cuda grammar but with tree-sitter-cpp's font-lock/indentation rules

From: Yuan Fu <[email-masked]>
Date: Fri, 17 Jan 2025 17:29:00 -0800

> On Jan 17, 2025, at 5:04 PM, Yuan Fu <[email-masked]> wrote:
> 
> 
> 
>> On Jan 16, 2025, at 11:35 AM, Ergus <[email-masked]> wrote:
>> 
>> Hi Yuan:
>> 
>> It has been a long time since this emails.. But today finally I made my
>> serious attempt to make a `cuda-ts-mode`.
>> 
>> While the treesit-language-remap-alist helped to reuse an important part
>> of the code, there were a few issues I needed to manage manually and
>> maybe they could be improved somehow:
>> 
>> 1. The indentation rules still uses the 'cpp prefix, so I had to
>> manually tune the code:
>> 
>> ```
>> (defun cuda-ts-mode--simple-indent-rules ()
>> (let ((cpp-rules (c-ts-mode--simple-indent-rules
>>   'cpp c-ts-mode-indent-style)))
>>   `((cuda . ,(alist-get 'cpp cpp-rules)))))
>> 
>> 
>> (setq-local treesit-simple-indent-rules
>> (cuda-ts-mode--simple-indent-rules))
>> ```
>> 
>> In order to manage it properly
>> 
>> 2. I see that font-lock is working, but the fontlock rules check is
>> using the cpp parser.
>> 
>> That's because the c-ts-mode--font-lock-settings still receives cpp as input.
>> I am trying to find a way to get it from c++ and then change the
>> :language cpp
>> with
>> :language cuda
>> because if I call
>> (c-ts-mode--font-lock-settings 'cuda) I obviously get an error.
>> 
>> Is there some way to go around these in a cleaner way?
> 
> Thanks Ergus, once you map a language to another, it should be transparent, and you shouldn’t need to change cpp to cuda. It’s most likely a bug somewhere. I’ll fix it.
> 
> Yuan

Ok, now using c-ts-mode’s font-lock and indentation rules verbatim should work. BTW, you should have

(setq-local treesit-language-remap-alist '((cpp . cuda)))

in cuda-ts-mode’s body.

Yuan