Skip to content
Rust development environment for Emacs
Emacs Lisp
Branch: master
Clone or download
Latest commit a0b27dc Sep 18, 2019


MELPA Build Status

Table of Contents


This package is a fork of rust-mode

Differences with rust-mode:

  • rust-analyzer configuration
  • flycheck integration
  • cargo popup
  • multiline error parsing
  • translation of ANSI control sequences through xterm-color
  • async org babel
  • custom compilation process
  • rustfmt errors in a rust compilation mode
  • automatic RLS configuration with eglot or lsp-mode
  • cask for testing
  • requires emacs 26
  • etc.


Simply put (use-package rustic) in your config and most stuff gets configured automatically.

If you have rust-mode installed, ensure it is required before rustic since it has to be removed from auto-mode-alist. However you only need rust-mode if you want to use emacs-racer. There's some stuff that isn't included in rustic.


Rustic defines a derived compilation-mode. Colors can be customized with several variables and you can also change the backtrace verbosity by changing the value of rustic-compile-backtrace.

Supported compile.el variables:

  • compilation-arguments
  • compilation-scroll-output (not first-error)


You can format your code with rustic-format-buffer or rustic-cargo-fmt. The variable rustic-format-on-save allows you to turn off auto-format on save. Rustic uses the function rustic-save-some-buffers for saving buffers before compilation. If you want buffers to be saved automatically, you can change the value of buffer-save-without-query.

Note: Rust edition 2018 requires a rustfmt.toml file.


You can disable LSP support by setting rustic-rls-pkg to nil.


RLS is the default and can be changed to rust-analyzer.

(setq rustic-lsp-server 'rust-analyzer)


The default package is lsp-mode. But you can also use eglot.

(setq rustic-lsp-client 'eglot)


rustic-rustfix runs rustfix, but it seems it's not very mature at this point. It would be a lot more helpful if we had an indicator for fixable errors and if it would be possible to run rustfix on a single file.


Rustic automatically configures a checker that runs clippy when flycheck is required. In case you use flymake, you have to take care of the configuration yourself.

Currently cargo does not display the correct installation command for some toolchains when clippy isn't installed. If you have problems try it with rustup component add --toolchain nightly clippy.

Use rustic-cargo-clippy to view the results in a derived compilation mode.


By default, rustic displays the number of errors and warnings in the mode-line. The variable rustic-flycheck-setup-mode-line-p can be set to nil to turn off mode-line modification.


The executed blocks run asynchronously and a running babel process is indicated by a spinner in the mode line. It can be turned off with rustic-display-spinner. If you prefer to see the output in a seperate buffer you can set rustic-babel-display-compilation-buffer to t.

After a successful build, source blocks get formatted by default. This can be changed with rustic-babel-format-src-block.

It's also possible to use crates in babel blocks.

#+BEGIN_SRC rustic :crates '((regex . 0.2))
  extern crate regex;

  use regex::Regex;

  fn main() {
      let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();

Supported org babel parameters:

Write to file :results file :file ~/babel-file


You can execute commands with rustic-popup. The list of commands can be customized with rustic-popup-commands. It's also possible to view the command's flags with h. The command rustic-popup-default-action (RET or TAB) allows you to change:

  • RUST_BACKTRACE environment variable
  • compilation-arguments for recompile
  • arguments for cargo test

Cargo outdated

Use rustic-cargo-outdated to get a list of dependencies that are out of date. The results are displayed in tabulated-list-mode and you can use most commands you know from the emacs package menu. This option requires the rust package cargo-outdated to be installed before being used.

  • u mark single crate for upgrade
  • U mark all upgradable crates
  • m remove mark
  • x perform marked package menu actions
  • r refresh crate list
  • q quit window


To run the tests, you will need Cask.

$ cask
$ cask exec ert-runner


PRs, feature requests and bug reports are very welcome.

You can’t perform that action at this time.