[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 081e62d08c 2/4: Support envrc for rustfmt
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 081e62d08c 2/4: Support envrc for rustfmt |
Date: |
Tue, 20 Dec 2022 15:00:32 -0500 (EST) |
branch: elpa/rust-mode
commit 081e62d08c08ed5281474a44beb12dc75688cb4d
Author: amesgen <amesgen@amesgen.de>
Commit: amesgen <amesgen@amesgen.de>
Support envrc for rustfmt
---
rust-rustfmt.el | 88 +++++++++++++++++++++++++++++----------------------------
1 file changed, 45 insertions(+), 43 deletions(-)
diff --git a/rust-rustfmt.el b/rust-rustfmt.el
index 9e53fe590c..ff5ba25188 100644
--- a/rust-rustfmt.el
+++ b/rust-rustfmt.el
@@ -41,49 +41,51 @@
(defun rust--format-call (buf)
"Format BUF using rustfmt."
- (with-current-buffer (get-buffer-create rust-rustfmt-buffername)
- (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))))
- ;; 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-and-window))
- ((= 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 %s buffer for
details"
- rust-rustfmt-buffername))
- (t
- (erase-buffer)
- (insert-file-contents tmpf)
- (rust--format-fix-rustfmt-buffer (buffer-name buf))
- (error "Rustfmt failed, see %s buffer for details"
- rust-rustfmt-buffername))))
- (delete-file tmpf)))))
+ (let ((path exec-path))
+ (with-current-buffer (get-buffer-create rust-rustfmt-buffername)
+ (setq-local exec-path path)
+ (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))))
+ ;; 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-and-window))
+ ((= 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 %s buffer for
details"
+ rust-rustfmt-buffername))
+ (t
+ (erase-buffer)
+ (insert-file-contents tmpf)
+ (rust--format-fix-rustfmt-buffer (buffer-name buf))
+ (error "Rustfmt failed, see %s buffer for details"
+ rust-rustfmt-buffername))))
+ (delete-file tmpf))))))
;; Since we run rustfmt through stdin we get <stdin> markers in the
;; output. This replaces them with the buffer name instead.