branch: elpa/rust-mode
commit 09efc45dee786cb220c233426ddd82b26ad950eb
Merge: 0985f5f 34cc528
Author: Tom Tromey <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #219 from Aankhen/highlight-question-mark
Highlight question mark operator using new `rust-question-mark-face'
---
rust-mode-tests.el | 32 ++++++++++++++++++++++++++++++++
rust-mode.el | 8 ++++++++
2 files changed, 40 insertions(+)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index b1d51c9..614340c 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1510,6 +1510,38 @@ this_is_not_a_string();)"
;; Only the i32 should have been highlighted.
'("i32" font-lock-type-face)))
+(ert-deftest font-lock-question-mark ()
+ "Ensure question mark operator is highlighted."
+ (rust-test-font-lock
+ "?"
+ '("?" rust-question-mark-face))
+ (rust-test-font-lock
+ "foo\(\)?;"
+ '("?" rust-question-mark-face))
+ (rust-test-font-lock
+ "foo\(bar\(\)?\);"
+ '("?" rust-question-mark-face))
+ (rust-test-font-lock
+ "\"?\""
+ '("\"?\"" font-lock-string-face))
+ (rust-test-font-lock
+ "foo\(\"?\"\);"
+ '("\"?\"" font-lock-string-face))
+ (rust-test-font-lock
+ "// ?"
+ '("// " font-lock-comment-delimiter-face
+ "?" font-lock-comment-face))
+ (rust-test-font-lock
+ "/// ?"
+ '("/// ?" font-lock-doc-face))
+ (rust-test-font-lock
+ "foo\(\"?\"\);"
+ '("\"?\"" font-lock-string-face))
+ (rust-test-font-lock
+ "foo\(\"?\"\)?;"
+ '("\"?\"" font-lock-string-face
+ "?" rust-question-mark-face)))
+
(ert-deftest rust-test-default-context-sensitive ()
(rust-test-font-lock
"let default = 7; impl foo { default fn f() { } }"
diff --git a/rust-mode.el b/rust-mode.el
index 2c58545..eac246f 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -165,6 +165,11 @@ function or trait. When nil, where will be aligned with
fn or trait."
"Face for the `unsafe' keyword."
:group 'rust-mode)
+(defface rust-question-mark-face
+ '((t :weight bold :inherit font-lock-builtin-face))
+ "Face for the question mark operator."
+ :group 'rust-mode)
+
(defun rust-paren-level () (nth 0 (syntax-ppss)))
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
@@ -603,6 +608,9 @@ the desired identifiers), but does not match type
annotations \"foo::<\"."
;; CamelCase Means Type Or Constructor
(,rust-re-type-or-constructor 1 font-lock-type-face)
+
+ ;; Question mark operator
+ ("\\?" . 'rust-question-mark-face)
)
;; Item definitions