From: Yuan Fu Date: Sat, 14 Sep 2024 18:07:28 +0000 (-0700) Subject: Fix c++-ts-mode font-lock for latest c++ grammar (bug#73191) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=709d7c5c43e6507fb31c3e9eb0ffd1dd6d6722e6;p=emacs.git 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. (cherry picked from commit 21efdd5ef31febc8fd59bf483a39bba512d50f45) --- diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 26b352874c2..804d0040f5c 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -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