Table of Contents
rust-mode
makes editing Rust code with Emacs
enjoyable. It requires Emacs 24 or later.
The package is available on MELPA. Add this to your init.el.
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(package-refresh-contents)
Now you can install rust-mode
with:
M-x package-install rust-mode
And put this in your config to load rust-mode automatically:
(require 'rust-mode)
straight.el clones each of your packages directly from its source. There are good additional installation instructions for moving your package management from package.el to straight.
Add this to your init.el:
(add-to-list 'load-path "/path/to/rust-mode/")
(autoload 'rust-mode "rust-mode" nil t)
The Rust style guide recommends spaces for indentation; to follow the recommendation add this to your init.el:
(add-hook 'rust-mode-hook
(lambda () (setq indent-tabs-mode nil)))
The rust-format-buffer
function will format your code with
rustfmt if installed. By default,
this is bound to C-c C-f
.
Placing (setq rust-format-on-save t)
in your init.el will enable automatic
running of rust-format-buffer
when you save a buffer.
The file rust-mode-tests.el
contains tests that can be run via
ERT.
You can use run_rust_emacs_tests.sh
to run them in batch mode, if
you set the environment variable EMACS to a program that runs emacs.
You can find more information in the lsp-mode wiki.
- cargo.el Emacs Minor Mode for Cargo, Rust's Package Manager
- emacs-racer Racer support for Emacs
- rustic Rust development environment for Emacs