Skip to content

Emacs minor mode which allows to dynamically select cargo command

License

Notifications You must be signed in to change notification settings

kodra-dev/cargo-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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 repository if you haven't already and install with M-x package-install RET cargo-mode RET.

Or you can use use-package:

(use-package cargo-mode
  :config
  (add-hook 'rust-mode-hook 'cargo-minor-mode))

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)

Usage

C-q e 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-q e t - cargo-mode-test - Run all tests in the project (cargo test).

C-q e l - cargo-mode-last-command - Execute the last executed command.

C-q e b - cargo-mode-build - Build the project (cargo build).

C-q e o - cargo-mode-test-current-buffer - Run all tests in the current buffer.

C-q e 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 prefix (default C-q e) use:

 (define-key cargo-minor-mode-map (kbd ...) 'cargo-mode-command-map)

Modify a command before execution

Use 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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 100.0%