summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2024-09-14 11:07:28 -0700
committerYuan Fu <casouri@gmail.com>2024-09-14 11:09:45 -0700
commit21efdd5ef31febc8fd59bf483a39bba512d50f45 (patch)
treedd3e52419850415a284c40dd21e3a44d7404d075
parentffc00eac53d88296e234d274ad1dd95bdf3cf065 (diff)
Fix c++-ts-mode font-lock for latest c++ grammar (bug#73191)
* 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.
-rw-r--r--lisp/progmodes/c-ts-mode.el16
1 files changed, 13 insertions, 3 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index f5cd36c68c7..a3379ad7aab 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -574,7 +574,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
@@ -592,6 +592,11 @@ MODE is either `c' or `cpp'."
"LIVE_BUFFER" "FRAME"))
"A regexp matching all the variants of the FOR_EACH_* macro.")
+(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'."
@@ -636,8 +641,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