Emacs minor mode which allows to dynamically select a Cargo command.
Cargo is the Rust package manager.
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))
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-compile-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 disable it.
(use-package cargo-mode
:custom
(cargo-mode-use-comint nil))
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)
Use prefix argument (default 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)