Skip to content

Commit 0d408d5

Browse files
authored
Merge pull request #253 from jjwest/master
Improved font-locking for print macros
2 parents b911835 + 705f3e4 commit 0d408d5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rust-mode-tests.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,19 @@ fn main() {
21932193
"\"\"" font-lock-string-face
21942194
"/* " font-lock-comment-delimiter-face
21952195
"print!(\"\"); */" font-lock-comment-face))
2196+
;; with newline directly following delimiter
2197+
(rust-test-font-lock
2198+
"print!(\n\"\"\n); { /* print!(\"\"); */ }"
2199+
'("print!" rust-builtin-formatting-macro-face
2200+
"\"\"" font-lock-string-face
2201+
"/* " font-lock-comment-delimiter-face
2202+
"print!(\"\"); */" font-lock-comment-face))
2203+
;; with empty println!()
2204+
(rust-test-font-lock
2205+
"println!(); { /* println!(); */ }"
2206+
'("println!" rust-builtin-formatting-macro-face
2207+
"/* " font-lock-comment-delimiter-face
2208+
"println!(); */" font-lock-comment-face))
21962209
;; other delimiters
21972210
(rust-test-font-lock
21982211
"print!{\"\"}; { /* no-op */ }"

rust-mode.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ match data if found. Returns nil if not within a Rust string."
633633
"List of builtin Rust macros for string formatting used by `rust-mode-font-lock-keywords'. (`write!' is handled separately.)")
634634

635635
(defvar rust-formatting-macro-opening-re
636-
"[[:space:]]*[({[][[:space:]]*"
636+
"[[:space:]\n]*[({[][[:space:]\n]*"
637637
"Regular expression to match the opening delimiter of a Rust formatting macro.")
638638

639639
(defvar rust-start-of-string-re
@@ -661,7 +661,7 @@ match data if found. Returns nil if not within a Rust string."
661661
1 font-lock-preprocessor-face keep)
662662

663663
;; Builtin formatting macros
664-
(,(concat (rust-re-grab (concat (regexp-opt rust-builtin-formatting-macros) "!")) (concat rust-formatting-macro-opening-re rust-start-of-string-re))
664+
(,(concat (rust-re-grab (concat (regexp-opt rust-builtin-formatting-macros) "!")) (concat rust-formatting-macro-opening-re "\\(?:" rust-start-of-string-re) "\\)?")
665665
(1 'rust-builtin-formatting-macro-face)
666666
(rust-string-interpolation-matcher
667667
(rust-end-of-string)

0 commit comments

Comments
 (0)