[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 39f32cc 447/486: In emacs >= 26.2, use replace-b
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 39f32cc 447/486: In emacs >= 26.2, use replace-buffer-contents after formatting |
Date: |
Sat, 7 Aug 2021 09:26:12 -0400 (EDT) |
branch: elpa/rust-mode
commit 39f32ccd6a1183df26a223a23db255a67076cd2d
Author: Trevor Spiteri <tspiteri@ieee.org>
Commit: Nathan Moreau <nathan.moreau@m4x.org>
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 save positions of direct and indirect buffers and windows.
This also 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.
---
rust-mode.el | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 1aa4e2e..9d6040b 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1463,7 +1463,13 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
((zerop ret)
(if (not (string= (buffer-string)
(with-current-buffer buf (buffer-string))))
- (copy-to-buffer buf (point-min) (point-max)))
+ ;; replace-buffer-contents was in emacs 26.1, but it
+ ;; was broken for non-ASCII strings, so we need 26.2.
+ (if (and (fboundp 'replace-buffer-contents)
+ (version<= "26.2" emacs-version))
+ (with-current-buffer buf
+ (replace-buffer-contents rust-rustfmt-buffername))
+ (copy-to-buffer buf (point-min) (point-max))))
(kill-buffer))
((= ret 3)
(if (not (string= (buffer-string)
@@ -1661,12 +1667,16 @@ Return the created process."
(pop-to-buffer (current-buffer)))
(message "rustfmt check passed."))))
-(defun rust-format-buffer ()
- "Format the current buffer using rustfmt."
- (interactive)
- (unless (executable-find rust-rustfmt-bin)
- (error "Could not locate executable \"%s\"" rust-rustfmt-bin))
+(defun rust--format-buffer-using-replace-buffer-contents ()
+ (condition-case err
+ (progn
+ (rust--format-call (current-buffer))
+ (message "Formatted buffer with rustfmt."))
+ (error
+ (or (rust--format-error-handler)
+ (signal (car err) (cdr err))))))
+(defun rust--format-buffer-saving-position-manually ()
(let* ((current (current-buffer))
(base (or (buffer-base-buffer current) current))
buffer-loc
@@ -1714,6 +1724,18 @@ Return the created process."
(or (rust--format-error-handler)
(signal (car err) (cdr err)))))))
+(defun rust-format-buffer ()
+ "Format the current buffer using rustfmt."
+ (interactive)
+ (unless (executable-find rust-rustfmt-bin)
+ (error "Could not locate executable \"%s\"" rust-rustfmt-bin))
+ ;; If emacs version >= 26.2, we can use replace-buffer-contents to
+ ;; preserve location and markers in buffer, otherwise we can try to
+ ;; save locations as best we can, though we still lose markers.
+ (if (version<= "26.2" emacs-version)
+ (rust--format-buffer-using-replace-buffer-contents)
+ (rust--format-buffer-saving-position-manually)))
+
(defun rust-enable-format-on-save ()
"Enable formatting using rustfmt when saving buffer."
(interactive)
- [nongnu] elpa/rust-mode e9e9e32 472/486: Add release build/run functions, (continued)
- [nongnu] elpa/rust-mode e9e9e32 472/486: Add release build/run functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e006788 474/486: Add .dir-locals.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7fdb9c2 450/486: Use <kbd> to indicate keyboard input in README (#375), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d211e68 453/486: Fix various byte compilation warnings in rust-mode-tests.el., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bded667 457/486: Add missing ‘require’ form., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 139a658 482/486: Create rust-rustfmt.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 494d59f 486/486: Make most additional libraries optional, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9f3d8cf 432/486: rust format buffer now saves position across multiple frames (#348), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6f1abc3 438/486: Expand README to include more information about features (#358), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e04e485 441/486: rustc-compilation-regexps: handle `note` case as compilation-info., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 39f32cc 447/486: In emacs >= 26.2, use replace-buffer-contents after formatting,
ELPA Syncer <=
- [nongnu] elpa/rust-mode eca55c0 451/486: Check for -> and => early in rust-ordinary-lt-gt-p, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ca7d99c 469/486: Set default directory when compiling., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c5c7ed3 471/486: Update README.md, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4e394ac 475/486: Add Makefile, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 09b4320 476/486: test: Suppress some noisy messages, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode afeddec 325/486: Merge pull request #224 from tromey/beginning-of-defun, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7fd78f0 444/486: rust-goto-format-problem: make sure to always just to a buffer that exists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9e03890 478/486: Create rust-compile.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 41642f0 481/486: rust-end-of-string: Move definition, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d548425 483/486: Create rust-playpen.el from existing code, ELPA Syncer, 2021/08/07