Skip to content

Commit 80cdc54

Browse files
sergvbrotzeit
authored andcommitted
Improve rust--format-fix-rustfmt-buffer
1 parent d0c1ffa commit 80cdc54

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

rust-rustfmt.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@
8686
;; Since we run rustfmt through stdin we get <stdin> markers in the
8787
;; output. This replaces them with the buffer name instead.
8888
(defun rust--format-fix-rustfmt-buffer (buffer-name)
89-
(with-current-buffer (get-buffer rust-rustfmt-buffername)
90-
(let ((inhibit-read-only t))
91-
(goto-char (point-min))
92-
(while (re-search-forward "--> <stdin>:" nil t)
93-
(replace-match (format "--> %s:" buffer-name)))
94-
(while (re-search-forward "--> stdin:" nil t)
95-
(replace-match (format "--> %s:" buffer-name))))))
89+
(save-match-data
90+
(with-current-buffer (get-buffer rust-rustfmt-buffername)
91+
(let ((inhibit-read-only t)
92+
(fixed (format "--> %s:" buffer-name)))
93+
(goto-char (point-min))
94+
(while (re-search-forward "--> \\(?:<stdin>\\|stdin\\):" nil t)
95+
(replace-match fixed))))))
9696

9797
;; If rust-mode has been configured to navigate to source of the error
9898
;; or display it, do so -- and return true. Otherwise return nil to

0 commit comments

Comments
 (0)