Skip to content

Commit 32a962a

Browse files
tspiteribrotzeit
authored andcommitted
In emacs >= 26.2, use replace-buffer-contents after formatting
This saves the position and the markers in the buffer, so there is no need to go to rustic-save-pos. This plays better with e.g. grep, as otherwise all grep markers would be destroyed when replacing the contents of the buffer with copy-to-buffer. While replace-buffer-contents was added in Emacs 26.1, it was broken for non-ASCII contents and would corrupt the buffer contents. This was fixed in 26.2, so we require version 26.2 for this.
1 parent 99966b9 commit 32a962a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rustic-util.el

+9-3
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ Use `:command' when formatting files and `:stdin' for strings."
103103
(inhibit-read-only t))
104104
(with-current-buffer proc-buffer
105105
(if (string-match-p "^finished" output)
106-
(let ((file-buffer next-error-last-buffer))
107-
(copy-to-buffer file-buffer (point-min) (point-max))
106+
(let ((file-buffer next-error-last-buffer)
107+
;; replace-buffer-contents was in emacs 26.1, but it
108+
;; was broken for non-ASCII strings, so we need 26.2.
109+
(use-replace (version<= "26.2" emacs-version)))
110+
(unless use-replace
111+
(copy-to-buffer file-buffer (point-min) (point-max)))
108112
(with-current-buffer file-buffer
109-
(goto-char rustic-save-pos))
113+
(if use-replace
114+
(replace-buffer-contents proc-buffer)
115+
(goto-char rustic-save-pos)))
110116
(kill-buffer proc-buffer)
111117
(message "Formatted buffer with rustfmt."))
112118
(goto-char (point-min))

0 commit comments

Comments
 (0)