Skip to content

Instantly share code, notes, and snippets.

@ckoparkar
Last active November 12, 2015 09:43
Show Gist options
  • Save ckoparkar/733dc0c4d4170380b6ec to your computer and use it in GitHub Desktop.
Save ckoparkar/733dc0c4d4170380b6ec to your computer and use it in GitHub Desktop.
Integrate rustfmt with emacs.
  1. 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

  2. Then install rustfmt,

    $ cargo install --git https://github.com/rust-lang-nursery/rustfmt

  3. Install emacs-rustfmt

    Add (depends-on "rustfmt") to your Cask file, and run Cask. Or manually add rustfmt.el to your load path.

And install rust-mode

  1. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment