ayrat555 / cargo-mode

Emacs minor mode which allows to dynamically select cargo command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cargo-mode.el

Emacs minor mode which allows to dynamically select a Cargo command.

Cargo is the Rust package manager.

Demo

Simple example (cargo clippy)

Clippy

Example with custom params (cargo doc --open)

Doc

Installation

MELPA

Set up the MELPA (or MELPA Stable) if you haven't already, and install with M-x package-install RET cargo-mode RET.

The relevant form for use-package users is:

(use-package cargo-mode
  :hook
  (rust-mode . cargo-minor-mode)
  :config
  (setq compilation-scroll-output t))

From file

Add cargo-mode.el to your load path:

(add-to-list 'load-path "path/to/cargo-mode.el")

Setup

Add a hook to the mode that you're using with Rust, for example, rust-mode:

(add-hook 'rust-mode-hook 'cargo-minor-mode)

Set compilation-scroll-output to non-nil to scroll the cargo-mode buffer window as output appears. The value ‘first-error’ stops scrolling at the first error, and leaves point on its location in the cargo-mode buffer. For example:

(setq compilation-scroll-output t)

By default cargo-mode use comint mode for compilation buffer. Set cargo-mode-use-comint to nil to use compilation mode instead.

(use-package cargo-mode
  :custom
  (cargo-mode-use-comint nil))

Usage

C-c a e - cargo-execute-task - List all available tasks and execute one of them. As a bonus, you'll get a documentation string because cargo-mode.el parses shell output of cargo --list directly.

C-c a t - cargo-mode-test - Run all tests in the project (cargo test).

C-c a l - cargo-mode-last-command - Execute the last executed command.

C-c a b - cargo-mode-build - Build the project (cargo build).

C-c a o - cargo-mode-test-current-buffer - Run all tests in the current buffer.

C-c a f - cargo-mode-test-current-test - Run the current test where pointer is located.

These are all commands that I use most frequently. You can execute any cargo command (fmt, clean etc) available in the project using cargo-mode-execute-task. If you have suggestions for additional commands to add keybindings to, please create an issue.

To change the prefix (default C-c a) use:

 (keymap-set cargo-minor-mode-map (kbd ...) 'cargo-mode-command-map)

Modify a command before execution

Use prefix argument (default C-u) to add extra command line params before executing a command.

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Ayrat Badykov (@ayrat555)

About

Emacs minor mode which allows to dynamically select cargo command

License:MIT License


Languages

Language:Emacs Lisp 100.0%