branch: elpa/rust-mode
commit 705f3e40a818d6b293c2460a7e6e2985c400a654
Author: Jonas Westlund <[email protected]>
Commit: Jonas Westlund <[email protected]>

    Improved font-locking for print macros
---
 rust-mode-tests.el | 13 +++++++++++++
 rust-mode.el       |  4 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index b2e8338..762c5f8 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -2186,6 +2186,19 @@ fn main() {
      "\"\"" 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
+     "\"\"" 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
+     "/* " font-lock-comment-delimiter-face
+     "println!(); */" font-lock-comment-face))
   ;; other delimiters
   (rust-test-font-lock
    "print!{\"\"}; { /* no-op */ }"
diff --git a/rust-mode.el b/rust-mode.el
index 82bcc50..ac9cb91 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -633,7 +633,7 @@ match data if found. Returns nil if not within a Rust 
string."
   "List of builtin Rust macros for string formatting used by 
`rust-mode-font-lock-keywords'. (`write!' is handled separately.)")
 
 (defvar rust-formatting-macro-opening-re
-  "[[:space:]]*[({[][[:space:]]*"
+  "[[:space:]\n]*[({[][[:space:]\n]*"
   "Regular expression to match the opening delimiter of a Rust formatting 
macro.")
 
 (defvar rust-start-of-string-re
@@ -661,7 +661,7 @@ match data if found. Returns nil if not within a Rust 
string."
       1 font-lock-preprocessor-face keep)
 
      ;; Builtin formatting macros
-     (,(concat (rust-re-grab (concat (regexp-opt 
rust-builtin-formatting-macros) "!")) (concat rust-formatting-macro-opening-re 
rust-start-of-string-re))
+     (,(concat (rust-re-grab (concat (regexp-opt 
rust-builtin-formatting-macros) "!")) (concat rust-formatting-macro-opening-re 
"\\(?:" rust-start-of-string-re) "\\)?")
       (1 'rust-builtin-formatting-macro-face)
       (rust-string-interpolation-matcher
        (rust-end-of-string)

Reply via email to