Skip to content

Commit

Permalink
In emacs >= 26.2, use replace-buffer-contents after formatting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tspiteri authored and brotzeit committed Apr 27, 2020
1 parent 99966b9 commit 32a962a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rustic-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ Use `:command' when formatting files and `:stdin' for strings."
(inhibit-read-only t))
(with-current-buffer proc-buffer
(if (string-match-p "^finished" output)
(let ((file-buffer next-error-last-buffer))
(copy-to-buffer file-buffer (point-min) (point-max))
(let ((file-buffer next-error-last-buffer)
;; replace-buffer-contents was in emacs 26.1, but it
;; was broken for non-ASCII strings, so we need 26.2.
(use-replace (version<= "26.2" emacs-version)))
(unless use-replace
(copy-to-buffer file-buffer (point-min) (point-max)))
(with-current-buffer file-buffer
(goto-char rustic-save-pos))
(if use-replace
(replace-buffer-contents proc-buffer)
(goto-char rustic-save-pos)))
(kill-buffer proc-buffer)
(message "Formatted buffer with rustfmt."))
(goto-char (point-min))
Expand Down

0 comments on commit 32a962a

Please sign in to comment.