Subject: Re: bug#71518: 30.0.50; Errors during redisplay with c++-ts-mode

From: Vincenzo Pupillo <[email-masked]>
Date: Sat, 22 Jun 2024 19:59:42 +0200

In data sabato 22 giugno 2024 19:03:43 CEST, Eli Zaretskii ha scritto:
> > Cc: [email-masked], [email-masked]
> > Date: Sat, 22 Jun 2024 19:56:34 +0300
> > From: Eli Zaretskii <[email-masked]>
> > 
> > Hmm... I still see an error message in *Messages* after installing
> > 
> > this (I have grammar library version 0.22.2):
> >   Error during redisplay: (jit-lock-function 1) signaled
> >   (treesit-query-error "Node type error at" 2 "(virtual)
> >   @font-lock-keyword-face [\"auto\" \"_Atomic\" \"break\" \"case\"
> >   \"const\" \"continue\" \"default\" \"do\" \"else\" \"enum\" \"extern\"
> >   \"for\" \"goto\" \"if\" \"inline\" \"register\" \"restrict\" \"return\"
> >   \"sizeof\" \"static\" \"struct\" \"switch\" \"typedef\" \"union\"
> >   \"volatile\" \"while\"] @font-lock-keyword-face" "Debug the query with
> >   `treesit-query-validate'")> 
> > Any ideas or suggestions?  "virtual" is highlighted, though, so I
> > guess this is a matter of suppressing the errors or something?
> 
> E.g., you can see in go-ts-mode.el how the code probes whether a
> certain query is supported, and uses it only if it is.
Sorry, I only tested with .cpp files.
The rule had to be protected by (when (eq mode 'cpp)...

Now I have tested this with *.c and *.h as well, with old and new grammar.

Thanks
Vincenzo

>From f518a28117c0418dc11bc4d9312df6609272813b Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Sat, 22 Jun 2024 16:22:16 +0200
Subject: [PATCH] Fix for grammar change of keyword "virtual" in
 tree-sitter-cpp

The new rule works with both the new (>= 0.22.1) and the old (<= 0.22.0)
grammar.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--keywords):
  Removed the keyword "virtual".
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings):
  New font lock rule. (Bug#71518)
---
 lisp/progmodes/c-ts-mode.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index f453392ff7f..e7f74fc53f2 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -572,7 +572,7 @@ c-ts-mode--keywords
                   "not" "not_eq" "operator" "or"
                   "or_eq" "override" "private" "protected"
                   "public" "requires" "template" "throw"
-                  "try" "typename" "using" "virtual"
+                  "try" "typename" "using"
                   "xor" "xor_eq"))
       (append '("auto") c-keywords))))
 
@@ -635,7 +635,8 @@ c-ts-mode--font-lock-settings
    `([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face
      ,@(when (eq mode 'cpp)
          '((auto) @font-lock-keyword-face
-           (this) @font-lock-keyword-face)))
+           (this) @font-lock-keyword-face
+           (virtual) @font-lock-keyword-face)))
 
    :language mode
    :feature 'operator
-- 
2.45.2