[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode a364b24 445/486: Make *rustfmt* buffer readonly.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode a364b24 445/486: Make *rustfmt* buffer readonly. |
Date: |
Sat, 7 Aug 2021 09:26:11 -0400 (EDT) |
branch: elpa/rust-mode
commit a364b24af412659cc1074f533752356d1858b893
Author: Nathan Moreau <nathan.moreau@m4x.org>
Commit: Nathan Moreau <nathan.moreau@m4x.org>
Make *rustfmt* buffer readonly.
---
rust-mode.el | 77 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 40 insertions(+), 37 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 9d17cc0..631e51c 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1445,48 +1445,51 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(defun rust--format-call (buf)
"Format BUF using rustfmt."
(with-current-buffer (get-buffer-create rust-rustfmt-buffername)
- (erase-buffer)
- (insert-buffer-substring buf)
- (let* ((tmpf (make-temp-file "rustfmt"))
- (ret (apply 'call-process-region
- (point-min)
- (point-max)
- rust-rustfmt-bin
- t
- `(t ,tmpf)
- nil
- rust-rustfmt-switches)))
- (unwind-protect
- (cond
- ((zerop ret)
- (if (not (string= (buffer-string)
- (with-current-buffer buf (buffer-string))))
- (copy-to-buffer buf (point-min) (point-max)))
- (kill-buffer))
- ((= ret 3)
- (if (not (string= (buffer-string)
- (with-current-buffer buf (buffer-string))))
- (copy-to-buffer buf (point-min) (point-max)))
- (erase-buffer)
- (insert-file-contents tmpf)
- (rust--format-fix-rustfmt-buffer (buffer-name buf))
- (error "Rustfmt could not format some lines, see *rustfmt* buffer
for details"))
- (t
- (erase-buffer)
- (insert-file-contents tmpf)
- (rust--format-fix-rustfmt-buffer (buffer-name buf))
- (error "Rustfmt failed, see *rustfmt* buffer for details"))))
- (delete-file tmpf))))
+ (view-mode +1)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert-buffer-substring buf)
+ (let* ((tmpf (make-temp-file "rustfmt"))
+ (ret (apply 'call-process-region
+ (point-min)
+ (point-max)
+ rust-rustfmt-bin
+ t
+ `(t ,tmpf)
+ nil
+ rust-rustfmt-switches)))
+ (unwind-protect
+ (cond
+ ((zerop ret)
+ (if (not (string= (buffer-string)
+ (with-current-buffer buf (buffer-string))))
+ (copy-to-buffer buf (point-min) (point-max)))
+ (kill-buffer))
+ ((= ret 3)
+ (if (not (string= (buffer-string)
+ (with-current-buffer buf (buffer-string))))
+ (copy-to-buffer buf (point-min) (point-max)))
+ (erase-buffer)
+ (insert-file-contents tmpf)
+ (rust--format-fix-rustfmt-buffer (buffer-name buf))
+ (error "Rustfmt could not format some lines, see *rustfmt*
buffer for details"))
+ (t
+ (erase-buffer)
+ (insert-file-contents tmpf)
+ (rust--format-fix-rustfmt-buffer (buffer-name buf))
+ (error "Rustfmt failed, see *rustfmt* buffer for details"))))
+ (delete-file tmpf)))))
;; Since we run rustfmt through stdin we get <stdin> 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)
- (goto-char (point-min))
- (while (re-search-forward "--> <stdin>:" nil t)
- (replace-match (format "--> %s:" buffer-name)))
- (while (re-search-forward "--> stdin:" nil t)
- (replace-match (format "--> %s:" buffer-name)))))
+ (let ((inhibit-read-only t))
+ (goto-char (point-min))
+ (while (re-search-forward "--> <stdin>:" nil t)
+ (replace-match (format "--> %s:" buffer-name)))
+ (while (re-search-forward "--> stdin:" nil t)
+ (replace-match (format "--> %s:" buffer-name))))))
;; 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
- [nongnu] elpa/rust-mode 74c2647 411/486: Highlight variable name in a for-loop (#326), (continued)
- [nongnu] elpa/rust-mode 74c2647 411/486: Highlight variable name in a for-loop (#326), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bb9bbd2 413/486: readme: recommend setting indent-tabs-mode to nil, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6dca073 414/486: readme: make other useful packages a list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7960c74 417/486: Do not allow subword-match when detecting built-in formatting macros, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5ad9b59 418/486: subword-match for built-in formatting macros: add a test., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 484d675 419/486: Adding GitHub actions., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c5ab165 423/486: mention LSP support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a36bc70 426/486: Merge pull request #340 from brotzeit/readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6a57253 427/486: rust-dbg-wrap-or-unwrap: bind to C-c C-d rather than C-c d., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e8345f6 440/486: Add triagebot configuration (#364), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a364b24 445/486: Make *rustfmt* buffer readonly.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 15a077a 458/486: rustc-colon-compilation-regexps: improve highlighting., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 00177f5 461/486: compile-mode integration: add link to code references. (#391), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5585cf9 477/486: rust-mode: Cosmetics, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3fa8f0b 479/486: Add non-empty commentary section, slightly reword summary, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7ff04a8 337/486: Merge pull request #234 from jjwest/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 70ff9a0 421/486: electric-pair-mode: prevent self-insert of `>' when already inserted. (#337), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4fd637c 428/486: rust-insert-dbg: handle the case of string literals. (#342), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 844bb51 429/486: add support for "async fn", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 63ec74c 434/486: Enforce use of spaces for indentation and cleanup whitespace (#353), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a36c96a 435/486: integrate rustfmt error messages, ELPA Syncer, 2021/08/07