Giter Site home page Giter Site logo

rust-mode's Introduction

MELPA

Table of Contents

Introduction

rust-mode makes editing Rust code with Emacs enjoyable. It requires Emacs 24 or later, and is include in both Emacs Prelude and Spacemacs by default.

This mode provides:

  • Syntax highlighting (for Font Lock Mode)
  • Indentation
  • Integration with Cargo, clippy and rustfmt

This mode does not provide autocompletion, or jumping to function / trait definitions. See Integration with Rust Language Server below for tips on how to enable this.

Installation

Melpa

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)

Manual installation

Clone this repository locally, and add this to your init.el:

(add-to-list 'load-path "/path/to/rust-mode/")
(autoload 'rust-mode "rust-mode" nil t)

Feature guide

Indentation

Commands like should indent correctly.

The Rust style guide recommends spaces rather than tabs for indentation; to follow the recommendation add this to your init.el, which forces indentation to always use spaces.

(add-hook 'rust-mode-hook
          (lambda () (setq indent-tabs-mode nil)))

Code formatting

The rust-format-buffer function will format your code with rustfmt if installed. By default, this is bound to C-c C-f.

The variable rust-format-on-save enables automatic formatting on save. For example, add the following in your init.el to enable format on save:

(setq rust-format-on-save t)

Running / testing / compiling code

The rust-run, rust-test and rust-build functions shell out to Cargo to run, test or build your code. Under the hood, these use the standard Emacs compile function.

These are not bound by default. To bind these to keyboard shortcuts, you can use the following in your init.el:

(define-key rust-mode-map (kbd "C-c C-c") 'rust-run)

Clippy

rust-run-clippy runs Clippy, a linter.

Easy insertion of !dbg

rust-dbg-wrap-or-unwrap either wraps or unwraps the current region in dbg!. This can be useful for easily adding debug lines to your program.

This is bound to C-c C-d by default.

Other recommended packages

Auto-completion / code navigation

This package does not provide integration with RLS, which provides auto-completion and code navigation. To use this you need an Emacs package that supports LSP.

Two examples are:

A lighter package that uses racer is emacs-racer.

flycheck

flycheck allows highlighting compile errors and Clippy lints inline.

cargo.el

cargo.el provides a minor mode for integration with Cargo, Rust's package manager.

Rustic

rustic is a fork of rust-mode, extending it with other features such as integration with LSP and with flycheck.

For package maintainers

Tests

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.

rust-mode's People

Contributors

aankhen avatar alexcrichton avatar birkenfeld avatar bmastenbrook avatar brotzeit avatar brson avatar fmdkdd avatar graydon avatar hi-angel avatar huonw avatar jjwest avatar jld avatar komon avatar kraai avatar kurnevsky avatar micahchalmer avatar mmilenko avatar mookid avatar mpenet avatar mrbliss avatar msullivan avatar nikomatsakis avatar phillord avatar pnkfelix avatar stebalien avatar swsnr avatar tomjakubowski avatar tromey avatar tspiteri avatar wilfred avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.