summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-02-15 05:10:43 -0500
committerGitHub <noreply@github.com>2018-02-15 05:10:43 -0500
commit0d408d5fe5bae38f6463e78486eab4263d4ae40d (patch)
tree9c925fe79dcde0308de39f153c78ed34b2b9bd7f
parentb911835c8e431ec1523e71b73ffd82cd6b80157c (diff)
parent705f3e40a818d6b293c2460a7e6e2985c400a654 (diff)
downloadrust-mode-0d408d5fe5bae38f6463e78486eab4263d4ae40d.tar.gz
Merge pull request #253 from jjwest/master
Improved font-locking for print macros
-rw-r--r--rust-mode-tests.el13
-rw-r--r--rust-mode.el4
2 files changed, 15 insertions, 2 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 6c6e9af..fd29d5d 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -2193,6 +2193,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 a5987ed..0c31b6c 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)