Emacs minor mode which allows to dynamically select a Cargo command.
Cargo is the Rust package manager.
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))
Add cargo-mode.el
to your load path:
(add-to-list 'load-path "path/to/cargo-mode.el")
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)
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)
Use C-u
to add extra command line params before executing a command.
- 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
Ayrat Badykov (@ayrat555)