]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix c++-ts-mode font-lock for latest c++ grammar (bug#73191)
authorYuan Fu <casouri@gmail.com>
Sat, 14 Sep 2024 18:07:28 +0000 (11:07 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 16 Sep 2024 10:04:53 +0000 (12:04 +0200)
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--keywords): Add "thread_local" keyword.
(c-ts-mode--test-virtual-named-p): New function.
(c-ts-mode--font-lock-settings): Use named/anonymous "virtual" depending
on the grammar.

(cherry picked from commit 21efdd5ef31febc8fd59bf483a39bba512d50f45)

lisp/progmodes/c-ts-mode.el

index 26b352874c21e51113b26e51d8092847a196337e..804d0040f5c9f377f60c27e4402a8cd20007b83f 100644 (file)
@@ -577,7 +577,7 @@ MODE is either `c' or `cpp'."
                   "or_eq" "override" "private" "protected"
                   "public" "requires" "template" "throw"
                   "try" "typename" "using"
-                  "xor" "xor_eq"))
+                  "xor" "xor_eq" "thread_local"))
       (append '("auto") c-keywords))))
 
 (defvar c-ts-mode--type-keywords
@@ -599,6 +599,11 @@ MODE is either `c' or `cpp'."
   (rx (| "/**" "/*!" "//!" "///"))
   "A regexp that matches all doxygen comment styles.")
 
+(defun c-ts-mode--test-virtual-named-p ()
+  "Return t if the virtual keyword is a namded node, nil otherwise."
+  (ignore-errors
+    (progn (treesit-query-compile 'cpp "(virtual)" t) t)))
+
 (defun c-ts-mode--font-lock-settings (mode)
   "Tree-sitter font-lock settings.
 MODE is either `c' or `cpp'."
@@ -643,8 +648,13 @@ MODE is either `c' or `cpp'."
    `([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face
      ,@(when (eq mode 'cpp)
          '((auto) @font-lock-keyword-face
-           (this) @font-lock-keyword-face
-           (virtual) @font-lock-keyword-face)))
+           (this) @font-lock-keyword-face))
+     ,@(when (and (eq mode 'cpp)
+                  (c-ts-mode--test-virtual-named-p))
+         '((virtual) @font-lock-keyword-face))
+     ,@(when (and (eq mode 'cpp)
+                  (not (c-ts-mode--test-virtual-named-p)))
+         '("virtual" @font-lock-keyword-face)))
 
    :language mode
    :feature 'operator