diff options
| author | Yuan Fu | 2024-09-14 11:07:28 -0700 |
|---|---|---|
| committer | Yuan Fu | 2024-09-14 11:09:45 -0700 |
| commit | 21efdd5ef31febc8fd59bf483a39bba512d50f45 (patch) | |
| tree | dd3e52419850415a284c40dd21e3a44d7404d075 | |
| parent | ffc00eac53d88296e234d274ad1dd95bdf3cf065 (diff) | |
| download | emacs-21efdd5ef31febc8fd59bf483a39bba512d50f45.tar.gz emacs-21efdd5ef31febc8fd59bf483a39bba512d50f45.zip | |
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.el | 16 |
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'." | |||
| 574 | "or_eq" "override" "private" "protected" | 574 | "or_eq" "override" "private" "protected" |
| 575 | "public" "requires" "template" "throw" | 575 | "public" "requires" "template" "throw" |
| 576 | "try" "typename" "using" | 576 | "try" "typename" "using" |
| 577 | "xor" "xor_eq")) | 577 | "xor" "xor_eq" "thread_local")) |
| 578 | (append '("auto") c-keywords)))) | 578 | (append '("auto") c-keywords)))) |
| 579 | 579 | ||
| 580 | (defvar c-ts-mode--type-keywords | 580 | (defvar c-ts-mode--type-keywords |
| @@ -592,6 +592,11 @@ MODE is either `c' or `cpp'." | |||
| 592 | "LIVE_BUFFER" "FRAME")) | 592 | "LIVE_BUFFER" "FRAME")) |
| 593 | "A regexp matching all the variants of the FOR_EACH_* macro.") | 593 | "A regexp matching all the variants of the FOR_EACH_* macro.") |
| 594 | 594 | ||
| 595 | (defun c-ts-mode--test-virtual-named-p () | ||
| 596 | "Return t if the virtual keyword is a namded node, nil otherwise." | ||
| 597 | (ignore-errors | ||
| 598 | (progn (treesit-query-compile 'cpp "(virtual)" t) t))) | ||
| 599 | |||
| 595 | (defun c-ts-mode--font-lock-settings (mode) | 600 | (defun c-ts-mode--font-lock-settings (mode) |
| 596 | "Tree-sitter font-lock settings. | 601 | "Tree-sitter font-lock settings. |
| 597 | MODE is either `c' or `cpp'." | 602 | MODE is either `c' or `cpp'." |
| @@ -636,8 +641,13 @@ MODE is either `c' or `cpp'." | |||
| 636 | `([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face | 641 | `([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face |
| 637 | ,@(when (eq mode 'cpp) | 642 | ,@(when (eq mode 'cpp) |
| 638 | '((auto) @font-lock-keyword-face | 643 | '((auto) @font-lock-keyword-face |
| 639 | (this) @font-lock-keyword-face | 644 | (this) @font-lock-keyword-face)) |
| 640 | (virtual) @font-lock-keyword-face))) | 645 | ,@(when (and (eq mode 'cpp) |
| 646 | (c-ts-mode--test-virtual-named-p)) | ||
| 647 | '((virtual) @font-lock-keyword-face)) | ||
| 648 | ,@(when (and (eq mode 'cpp) | ||
| 649 | (not (c-ts-mode--test-virtual-named-p))) | ||
| 650 | '("virtual" @font-lock-keyword-face))) | ||
| 641 | 651 | ||
| 642 | :language mode | 652 | :language mode |
| 643 | :feature 'operator | 653 | :feature 'operator |