Skip to content
/ rustic Public
forked from brotzeit/rustic

Rust development environment for Emacs

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

clnbr/rustic

 
 

Repository files navigation

Rustic

MELPA Build Status

Table of Contents

Intro

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.

Installation

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.

Compilation

Rustic doesn't use compilation-start yet, since there seems to be no way to set coding-system-for-read and utf-8-emacs-unix.

Supported compile.el variables:

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

Rustfmt

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.

LSP

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

Server

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

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

Client

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

(setq rustic-rls-pkg 'eglot)

Rustfix

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.

Clippy

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.

Flycheck

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.

Org-babel

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();
      assert!(re.is_match("2014-01-01"));
  }
#+END_SRC

Supported org babel parameters:

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

Popup

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

Tests

To run the tests, you will need Cask.

$ cask
$ cask exec ert-runner

Contributing

PRs, feature requests and bug reports are very welcome.

About

Rust development environment for Emacs

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 100.0%