Awesome
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)
Example with custom params (cargo doc --open)
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
<kbd> C-c a e </kbd> - 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.
<kbd> C-c a t </kbd> - cargo-mode-test
- Run all tests in the project (cargo test
).
<kbd> C-c a l </kbd> - cargo-mode-last-command
- Execute the last executed command.
<kbd> C-c a b </kbd> - cargo-mode-build
- Build the project (cargo build
).
<kbd> C-c a o </kbd> - cargo-mode-test-current-buffer
- Run all tests in the current buffer.
<kbd> C-c a f </kbd> - 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 <kbd>C-c a</kbd>) 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
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Author
Ayrat Badykov (@ayrat555)