Skip to content

Commit 09efc45

Browse files
authored
Merge pull request #219 from Aankhen/highlight-question-mark
Highlight question mark operator using new `rust-question-mark-face'
2 parents 0985f5f + 34cc528 commit 09efc45

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

rust-mode-tests.el

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,38 @@ this_is_not_a_string();)"
15101510
;; Only the i32 should have been highlighted.
15111511
'("i32" font-lock-type-face)))
15121512

1513+
(ert-deftest font-lock-question-mark ()
1514+
"Ensure question mark operator is highlighted."
1515+
(rust-test-font-lock
1516+
"?"
1517+
'("?" rust-question-mark-face))
1518+
(rust-test-font-lock
1519+
"foo\(\)?;"
1520+
'("?" rust-question-mark-face))
1521+
(rust-test-font-lock
1522+
"foo\(bar\(\)?\);"
1523+
'("?" rust-question-mark-face))
1524+
(rust-test-font-lock
1525+
"\"?\""
1526+
'("\"?\"" font-lock-string-face))
1527+
(rust-test-font-lock
1528+
"foo\(\"?\"\);"
1529+
'("\"?\"" font-lock-string-face))
1530+
(rust-test-font-lock
1531+
"// ?"
1532+
'("// " font-lock-comment-delimiter-face
1533+
"?" font-lock-comment-face))
1534+
(rust-test-font-lock
1535+
"/// ?"
1536+
'("/// ?" font-lock-doc-face))
1537+
(rust-test-font-lock
1538+
"foo\(\"?\"\);"
1539+
'("\"?\"" font-lock-string-face))
1540+
(rust-test-font-lock
1541+
"foo\(\"?\"\)?;"
1542+
'("\"?\"" font-lock-string-face
1543+
"?" rust-question-mark-face)))
1544+
15131545
(ert-deftest rust-test-default-context-sensitive ()
15141546
(rust-test-font-lock
15151547
"let default = 7; impl foo { default fn f() { } }"

rust-mode.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ function or trait. When nil, where will be aligned with fn or trait."
165165
"Face for the `unsafe' keyword."
166166
:group 'rust-mode)
167167

168+
(defface rust-question-mark-face
169+
'((t :weight bold :inherit font-lock-builtin-face))
170+
"Face for the question mark operator."
171+
:group 'rust-mode)
172+
168173
(defun rust-paren-level () (nth 0 (syntax-ppss)))
169174
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
170175
(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::<\"."
603608

604609
;; CamelCase Means Type Or Constructor
605610
(,rust-re-type-or-constructor 1 font-lock-type-face)
611+
612+
;; Question mark operator
613+
("\\?" . 'rust-question-mark-face)
606614
)
607615

608616
;; Item definitions

0 commit comments

Comments
 (0)