diff options
| -rw-r--r-- | rust-mode-tests.el | 100 | ||||
| -rw-r--r-- | rust-mode.el | 29 |
2 files changed, 69 insertions, 60 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el index c0e88fa..56ed369 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -1638,13 +1638,13 @@ this_is_not_a_string();)" "Ensure question mark operator is highlighted." (rust-test-font-lock "?" - '("?" rust-question-mark-face)) + '("?" rust-question-mark)) (rust-test-font-lock "foo\(\)?;" - '("?" rust-question-mark-face)) + '("?" rust-question-mark)) (rust-test-font-lock "foo\(bar\(\)?\);" - '("?" rust-question-mark-face)) + '("?" rust-question-mark)) (rust-test-font-lock "\"?\"" '("\"?\"" font-lock-string-face)) @@ -1664,7 +1664,7 @@ this_is_not_a_string();)" (rust-test-font-lock "foo\(\"?\"\)?;" '("\"?\"" font-lock-string-face - "?" rust-question-mark-face))) + "?" rust-question-mark))) (ert-deftest rust-test-default-context-sensitive () (rust-test-font-lock @@ -2250,165 +2250,165 @@ fn main() { ;; is ignored (rust-test-font-lock "print!(\"\"); { /* print!(\"\"); */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "print!(\"\"); */" font-lock-comment-face)) ;; with newline directly following delimiter (rust-test-font-lock "print!(\n\"\"\n); { /* print!(\"\"); */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "print!(\"\"); */" font-lock-comment-face)) ;; with empty println!() (rust-test-font-lock "println!(); { /* println!(); */ }" - '("println!" rust-builtin-formatting-macro-face + '("println!" rust-builtin-formatting-macro "/* " font-lock-comment-delimiter-face "println!(); */" font-lock-comment-face)) ;; other delimiters (rust-test-font-lock "print!{\"\"}; { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; other delimiters (rust-test-font-lock "print![\"\"]; { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; no interpolation (rust-test-font-lock "print!(\"abcd\"); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"abcd\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; only interpolation (rust-test-font-lock "print!(\"{}\"); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"" font-lock-string-face - "{}" rust-string-interpolation-face + "{}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; text + interpolation (rust-test-font-lock "print!(\"abcd {}\", foo); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{}" rust-string-interpolation-face + "{}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; text + interpolation with specification (rust-test-font-lock "print!(\"abcd {0}\", foo); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; text + interpolation with specification and escape (rust-test-font-lock "print!(\"abcd {0}}}\", foo); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation "}}\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; multiple pairs (rust-test-font-lock "print!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("print!" rust-builtin-formatting-macro-face + '("print!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; println (rust-test-font-lock "println!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("println!" rust-builtin-formatting-macro-face + '("println!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; eprint (rust-test-font-lock "eprint!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("eprint!" rust-builtin-formatting-macro-face + '("eprint!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; eprintln (rust-test-font-lock "eprintln!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("eprintln!" rust-builtin-formatting-macro-face + '("eprintln!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; format (rust-test-font-lock "format!(\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("format!" rust-builtin-formatting-macro-face + '("format!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; print + raw string (rust-test-font-lock "format!(r\"abcd {0} efgh {1}\", foo, bar); { /* no-op */ }" - '("format!" rust-builtin-formatting-macro-face + '("format!" rust-builtin-formatting-macro "r\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; print + raw string with hash (rust-test-font-lock "format!(r#\"abcd {0} efgh {1}\"#, foo, bar); { /* no-op */ }" - '("format!" rust-builtin-formatting-macro-face + '("format!" rust-builtin-formatting-macro "r#\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"#" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) ;; print + raw string with two hashes (rust-test-font-lock "format!(r##\"abcd {0} efgh {1}\"##, foo, bar); { /* no-op */ }" - '("format!" rust-builtin-formatting-macro-face + '("format!" rust-builtin-formatting-macro "r##\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation " efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"##" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face))) @@ -2416,29 +2416,29 @@ fn main() { (ert-deftest rust-write-macro-font-lock () (rust-test-font-lock "write!(f, \"abcd {0}}} efgh {1}\", foo, bar); { /* no-op */ }" - '("write!" rust-builtin-formatting-macro-face + '("write!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation "}} efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) (rust-test-font-lock "writeln!(f, \"abcd {0}}} efgh {1}\", foo, bar); { /* no-op */ }" - '("writeln!" rust-builtin-formatting-macro-face + '("writeln!" rust-builtin-formatting-macro "\"abcd " font-lock-string-face - "{0}" rust-string-interpolation-face + "{0}" rust-string-interpolation "}} efgh " font-lock-string-face - "{1}" rust-string-interpolation-face + "{1}" rust-string-interpolation "\"" font-lock-string-face "/* " font-lock-comment-delimiter-face "no-op */" font-lock-comment-face)) (rust-test-font-lock "println!(\"123\"); eprintln!(\"123\"); cprintln!(\"123\");" - '("println!" rust-builtin-formatting-macro-face + '("println!" rust-builtin-formatting-macro "\"123\"" font-lock-string-face - "eprintln!" rust-builtin-formatting-macro-face + "eprintln!" rust-builtin-formatting-macro "\"123\"" font-lock-string-face "cprintln!" font-lock-preprocessor-face "\"123\"" font-lock-string-face))) diff --git a/rust-mode.el b/rust-mode.el index e842b8e..9be46d2 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -117,22 +117,31 @@ to the function arguments. When nil, `->' will be indented one level." ;;; Faces -(defface rust-unsafe-face +(define-obsolete-face-alias 'rust-unsafe-face + 'rust-unsafe "0.6.0") +(define-obsolete-face-alias 'rust-question-mark-face + 'rust-question-mark "0.6.0") +(define-obsolete-face-alias 'rust-builtin-formatting-macro-face + 'rust-builtin-formatting-macro "0.6.0") +(define-obsolete-face-alias 'rust-string-interpolation-face + 'rust-string-interpolation "0.6.0") + +(defface rust-unsafe '((t :inherit font-lock-warning-face)) "Face for the `unsafe' keyword." :group 'rust-mode) -(defface rust-question-mark-face +(defface rust-question-mark '((t :weight bold :inherit font-lock-builtin-face)) "Face for the question mark operator." :group 'rust-mode) -(defface rust-builtin-formatting-macro-face +(defface rust-builtin-formatting-macro '((t :inherit font-lock-builtin-face)) "Face for builtin formatting macros (print! &c.)." :group 'rust-mode) -(defface rust-string-interpolation-face +(defface rust-string-interpolation '((t :slant italic :inherit font-lock-string-face)) "Face for interpolating braces in builtin formatting macro strings." :group 'rust-mode) @@ -401,7 +410,7 @@ Does not match type annotations of the form \"foo::<\"." (,(regexp-opt rust-special-types 'symbols) . font-lock-type-face) ;; The unsafe keyword - ("\\_<unsafe\\_>" . 'rust-unsafe-face) + ("\\_<unsafe\\_>" . 'rust-unsafe) ;; Attributes like `#[bar(baz)]` or `#![bar(baz)]` or `#[bar = "baz"]` (,(rust-re-grab (concat "#\\!?\\[" rust-re-ident "[^]]*\\]")) @@ -413,22 +422,22 @@ Does not match type annotations of the form \"foo::<\"." "!")) rust-formatting-macro-opening-re "\\(?:" rust-start-of-string-re "\\)?") - (1 'rust-builtin-formatting-macro-face) + (1 'rust-builtin-formatting-macro) (rust-string-interpolation-matcher (rust-end-of-string) nil - (0 'rust-string-interpolation-face t nil))) + (0 'rust-string-interpolation t nil))) ;; write! macro (,(concat (rust-re-grab (concat (rust-re-word "write\\(ln\\)?") "!")) rust-formatting-macro-opening-re "[[:space:]]*[^\"]+,[[:space:]]*" rust-start-of-string-re) - (1 'rust-builtin-formatting-macro-face) + (1 'rust-builtin-formatting-macro) (rust-string-interpolation-matcher (rust-end-of-string) nil - (0 'rust-string-interpolation-face t nil))) + (0 'rust-string-interpolation t nil))) ;; Syntax extension invocations like `foo!`, highlight including the ! (,(concat (rust-re-grab (concat rust-re-ident "!")) "[({[:space:][]") @@ -457,7 +466,7 @@ Does not match type annotations of the form \"foo::<\"." (,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1 font-lock-variable-name-face) ;; Question mark operator - ("\\?" . 'rust-question-mark-face) + ("\\?" . 'rust-question-mark) ) ;; Ensure we highlight `Foo` in `struct Foo` as a type. |
