diff options
| author | Nathan Moreau <nathan.moreau@m4x.org> | 2019-10-31 19:45:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-31 19:45:42 +0100 |
| commit | c0cc6dc75754fd607572a6fd72945d87729d0174 (patch) | |
| tree | 94ddc85274c13683e513dd721249457d016fff95 | |
| parent | 484d6754c51424e3b49461d54cfeac8fc05993b5 (diff) | |
| download | rust-mode-c0cc6dc75754fd607572a6fd72945d87729d0174.tar.gz | |
Allow pass custom flags to rustfmt. (#338)
* rust-rustfmt-switches: new defvar.
* rust-format-diff-buffer, rust--format-call: use the custom flags.
| -rw-r--r-- | rust-mode.el | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/rust-mode.el b/rust-mode.el index b361749..5c68640 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -165,6 +165,11 @@ to the function arguments. When nil, `->' will be indented one level." :type 'string :group 'rust-mode) +(defcustom rust-rustfmt-switches '("--edition" "2018") + "Arguments to pass when invoking the `rustfmt' executable." + :type '(repeat string) + :group 'rust-mode) + (defcustom rust-cargo-bin "cargo" "Path to cargo executable." :type 'string @@ -1354,8 +1359,14 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (erase-buffer) (insert-buffer-substring buf) (let* ((tmpf (make-temp-file "rustfmt")) - (ret (call-process-region (point-min) (point-max) rust-rustfmt-bin - t `(t ,tmpf) nil))) + (ret (apply 'call-process-region + (point-min) + (point-max) + rust-rustfmt-bin + t + `(t ,tmpf) + nil + rust-rustfmt-switches))) (unwind-protect (cond ((zerop ret) @@ -1465,16 +1476,20 @@ Return the created process." (interactive) (unless (executable-find rust-rustfmt-bin) (error "Could not locate executable \%s\"" rust-rustfmt-bin)) - (let ((proc - (start-process "rustfmt-diff" - (with-current-buffer - (get-buffer-create "*rustfmt-diff*") - (let ((inhibit-read-only t)) - (erase-buffer)) - (current-buffer)) - rust-rustfmt-bin - "--check" - (buffer-file-name)))) + (let* ((buffer + (with-current-buffer + (get-buffer-create "*rustfmt-diff*") + (let ((inhibit-read-only t)) + (erase-buffer)) + (current-buffer))) + (proc + (apply 'start-process + "rustfmt-diff" + buffer + rust-rustfmt-bin + "--check" + (cons (buffer-file-name) + rust-rustfmt-switches)))) (set-process-sentinel proc 'rust-format-diff-buffer-sentinel) proc)) |
