From 80cdc5417c3f6a6faf85f0d78c6d606c9aa39cb0 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Mon, 28 Jun 2021 19:39:21 +0100 Subject: Improve rust--format-fix-rustfmt-buffer --- rust-rustfmt.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'rust-rustfmt.el') diff --git a/rust-rustfmt.el b/rust-rustfmt.el index d3b7509..33f916d 100644 --- a/rust-rustfmt.el +++ b/rust-rustfmt.el @@ -86,13 +86,13 @@ ;; Since we run rustfmt through stdin we get markers in the ;; output. This replaces them with the buffer name instead. (defun rust--format-fix-rustfmt-buffer (buffer-name) - (with-current-buffer (get-buffer rust-rustfmt-buffername) - (let ((inhibit-read-only t)) - (goto-char (point-min)) - (while (re-search-forward "--> :" nil t) - (replace-match (format "--> %s:" buffer-name))) - (while (re-search-forward "--> stdin:" nil t) - (replace-match (format "--> %s:" buffer-name)))))) + (save-match-data + (with-current-buffer (get-buffer rust-rustfmt-buffername) + (let ((inhibit-read-only t) + (fixed (format "--> %s:" buffer-name))) + (goto-char (point-min)) + (while (re-search-forward "--> \\(?:\\|stdin\\):" nil t) + (replace-match fixed)))))) ;; If rust-mode has been configured to navigate to source of the error ;; or display it, do so -- and return true. Otherwise return nil to -- cgit v1.2.3