]> git.eshelyaron.com Git - emacs.git/commitdiff
Add font-locking for Rust macros (bug#70464)
authorNoah Peart <noah.v.peart@gmail.com>
Fri, 19 Apr 2024 01:22:05 +0000 (18:22 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 22 Apr 2024 18:37:36 +0000 (20:37 +0200)
* lisp/progmodes/rust-ts-mode.el
(rust-ts-mode--font-lock-settings): Add font-locking for Rust
macro metavariables, fragment specifiers and repitition patterns.

(cherry picked from commit 5c51bc934ebb88dd9dd8b228e99c39518c92c54b)

lisp/progmodes/rust-ts-mode.el

index 92978db64af14aec615880e0c2fd783740d54c13..25f1df4a9f9e6034d5e781224d10b6403f24ea39 100644 (file)
@@ -179,6 +179,8 @@ to be checked as its standard input."
      (function_signature_item name: (identifier) @font-lock-function-name-face)
      (macro_definition "macro_rules!" @font-lock-constant-face)
      (macro_definition (identifier) @font-lock-preprocessor-face)
+     (token_binding_pattern
+      name: (metavariable) @font-lock-variable-name-face)
      (field_declaration name: (field_identifier) @font-lock-property-name-face)
      (parameter pattern: (_) @rust-ts-mode--fontify-pattern)
      (closure_parameters (_) @rust-ts-mode--fontify-pattern)
@@ -219,7 +221,9 @@ to be checked as its standard input."
 
    :language 'rust
    :feature 'operator
-   `([,@rust-ts-mode--operators] @font-lock-operator-face)
+   `([,@rust-ts-mode--operators] @font-lock-operator-face
+     (token_repetition_pattern ["$" "*" "+"] @font-lock-operator-face)
+     (token_repetition ["$" "*" "+"] @font-lock-operator-face))
 
    :language 'rust
    :feature 'string
@@ -249,8 +253,7 @@ to be checked as its standard input."
                 (_ type: (scoped_identifier
                           path: (identifier) @font-lock-type-face))))
      (mod_item name: (identifier) @font-lock-constant-face)
-     (primitive_type) @font-lock-type-face
-     (type_identifier) @font-lock-type-face
+     [(fragment_specifier) (primitive_type) (type_identifier)] @font-lock-type-face
      ((scoped_identifier name: (identifier) @rust-ts-mode--fontify-tail))
      ((scoped_identifier path: (identifier) @font-lock-type-face)
       (:match ,(rx bos
@@ -260,8 +263,7 @@ to be checked as its standard input."
                    eos)
               @font-lock-type-face))
      ((scoped_identifier path: (identifier) @rust-ts-mode--fontify-scope))
-     ((scoped_type_identifier path: (identifier) @rust-ts-mode--fontify-scope))
-     (type_identifier) @font-lock-type-face)
+     ((scoped_type_identifier path: (identifier) @rust-ts-mode--fontify-scope)))
 
    :language 'rust
    :feature 'property
@@ -295,7 +297,8 @@ to be checked as its standard input."
      (return_expression (identifier) @font-lock-variable-use-face)
      (tuple_expression (identifier) @font-lock-variable-use-face)
      (unary_expression (identifier) @font-lock-variable-use-face)
-     (while_expression condition: (identifier) @font-lock-variable-use-face))
+     (while_expression condition: (identifier) @font-lock-variable-use-face)
+     (metavariable) @font-lock-variable-use-face)
 
    :language 'rust
    :feature 'escape-sequence