Function: c-ts-mode--font-lock-settings
c-ts-mode--font-lock-settings is a byte-compiled function defined in
c-ts-mode.el.gz.
Signature
(c-ts-mode--font-lock-settings MODE)
Documentation
Tree-sitter font-lock settings.
MODE is either c or cpp.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-mode.el.gz
(defun c-ts-mode--font-lock-settings (mode)
"Tree-sitter font-lock settings.
MODE is either `c' or `cpp'."
(treesit-font-lock-rules
:default-language mode
:feature 'comment
`(((comment) @font-lock-doc-face
(:match ,(rx bos "/**") @font-lock-doc-face))
(comment) @font-lock-comment-face)
:feature 'preprocessor
`((preproc_directive) @font-lock-preprocessor-face
(preproc_def
name: (identifier) @font-lock-variable-name-face)
(preproc_ifdef
name: (identifier) @font-lock-variable-name-face)
(preproc_function_def
name: (identifier) @font-lock-function-name-face)
(preproc_params
(identifier) @font-lock-variable-name-face)
(preproc_defined
"defined" @font-lock-preprocessor-face
"(" @font-lock-preprocessor-face
(identifier) @font-lock-variable-name-face
")" @font-lock-preprocessor-face)
[,@c-ts-mode--preproc-keywords] @font-lock-preprocessor-face)
:feature 'constant
`((true) @font-lock-constant-face
(false) @font-lock-constant-face
(null) @font-lock-constant-face)
:feature 'keyword
`([,@(c-ts-mode--keywords mode)] @font-lock-keyword-face
,@(when (eq mode 'cpp)
'((auto) @font-lock-keyword-face
(this) @font-lock-keyword-face))
,@(when (eq mode 'cpp)
(treesit-query-first-valid 'cpp
'((virtual) @font-lock-keyword-face)
'("virtual" @font-lock-keyword-face))))
:feature 'operator
`([,@c-ts-mode--operators
,@(when (eq mode 'cpp) c-ts-mode--c++-operators)]
@font-lock-operator-face
"!" @font-lock-negation-char-face)
:feature 'string
`((string_literal) @font-lock-string-face
(system_lib_string) @font-lock-string-face
,@(when (eq mode 'cpp)
'((raw_string_literal) @font-lock-string-face)))
:feature 'literal
`((number_literal) @font-lock-number-face
(char_literal) @font-lock-constant-face)
:feature 'type
`((primitive_type) @font-lock-type-face
(type_identifier) @font-lock-type-face
(sized_type_specifier) @font-lock-type-face
,@(when (eq mode 'cpp)
'((type_qualifier) @font-lock-type-face
(qualified_identifier
scope: (namespace_identifier) @font-lock-constant-face)
(operator_cast) type: (type_identifier) @font-lock-type-face
(namespace_identifier) @font-lock-constant-face))
[,@c-ts-mode--type-keywords] @font-lock-type-face)
:feature 'definition
;; Highlights identifiers in declarations.
`(,@(when (eq mode 'cpp)
'((destructor_name (identifier) @font-lock-function-name-face)))
(declaration
declarator: (_) @c-ts-mode--fontify-declarator)
(field_declaration
declarator: (_) @c-ts-mode--fontify-declarator)
(function_definition
declarator: (_) @c-ts-mode--fontify-declarator)
;; When a function definition has preproc directives in its body,
;; it can't correctly parse into a function_definition. We still
;; want to highlight the function_declarator correctly, hence
;; this rule. See bug#63390 for more detail.
((function_declarator) @c-ts-mode--fontify-declarator
(:pred c-ts-mode--top-level-declarator
@c-ts-mode--fontify-declarator))
(parameter_declaration
declarator: (_) @c-ts-mode--fontify-declarator)
(enumerator
name: (identifier) @font-lock-property-name-face))
:feature 'assignment
;; TODO: Recursively highlight identifiers in parenthesized
;; expressions, see `c-ts-mode--fontify-declarator' for
;; inspiration.
'((assignment_expression
left: (identifier) @font-lock-variable-use-face)
(assignment_expression
left: (field_expression field: (_) @font-lock-property-use-face))
(assignment_expression
left: (pointer_expression
(identifier) @font-lock-variable-use-face))
(assignment_expression
left: (subscript_expression
(identifier) @font-lock-variable-use-face))
(init_declarator declarator: (_) @c-ts-mode--fontify-declarator))
:feature 'function
'((call_expression
function:
[(identifier) @font-lock-function-call-face
(field_expression field: (field_identifier) @font-lock-function-call-face)]))
:feature 'variable
'((identifier) @c-ts-mode--fontify-variable)
:feature 'label
'((labeled_statement
label: (statement_identifier) @font-lock-constant-face))
:feature 'error
'((ERROR) @c-ts-mode--fontify-error)
:feature 'escape-sequence
:override t
'((escape_sequence) @font-lock-escape-face)
:feature 'property
'((field_identifier) @font-lock-property-use-face)
:feature 'bracket
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
:feature 'delimiter
'((["," ":" ";"]) @font-lock-delimiter-face)
:feature 'emacs-devel
:override t
`(((call_expression
(call_expression function: (identifier) @fn)
@c-ts-mode--fontify-DEFUN)
(:match "\\`DEFUN\\'" @fn))
((function_definition type: (_) @for-each-tail)
@c-ts-mode--fontify-for-each-tail
(:match ,c-ts-mode--for-each-tail-regexp @for-each-tail)))))