-
Install nightly build of cargo. (rustfmt requires cargo 0.6.0 or newer)
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
-
Then install rustfmt,
$ cargo install --git https://github.com/rust-lang-nursery/rustfmt
-
Install emacs-rustfmt
Add
(depends-on "rustfmt")
to your Cask file, and run Cask. Or manually addrustfmt.el
to your load path.
And install rust-mode
- Add this to your .emacs (or equivalent) file; to run rustfmt after every save.
(defun my-rust-mode-hooks ()
(add-hook 'before-save-hook 'rustfmt-format-buffer)
)
(add-hook 'rust-mode-hook 'my-rust-mode-hooks)
Or, add a keybinding,
(define-key rust-mode-map (kbd "C-c C-f") #'rustfmt-format-buffer)