Last active
August 29, 2015 14:09
-
-
Save viperscape/cec68f0791687f5959f1 to your computer and use it in GitHub Desktop.
rust lang, cargo/rustc run hotkeys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun rust-save-compile-and-run-this () | |
(interactive) | |
(save-buffer) | |
(compile | |
(format "rustc %s && %s" | |
(buffer-file-name) | |
(file-name-sans-extension (buffer-file-name))))) | |
(defun rust-save-compile-and-run () | |
(interactive) | |
(save-buffer) | |
(if (locate-dominating-file (buffer-file-name) "Cargo.toml") | |
(compile "cargo run") | |
(rust-save-compile-and-run-this))) | |
(defun cargo-test () | |
(interactive) | |
(save-buffer) | |
(if (locate-dominating-file (buffer-file-name) "Cargo.toml") | |
(compile "cargo test") | |
(rust-save-compile-and-run-this))) | |
(defun cargo-bench () | |
(interactive) | |
(save-buffer) | |
(if (locate-dominating-file (buffer-file-name) "Cargo.toml") | |
(compile "cargo bench") | |
(rust-save-compile-and-run-this))) | |
(add-hook 'rust-mode-hook | |
(lambda () | |
(define-key rust-mode-map (kbd "<f5>") 'rust-save-compile-and-run))) | |
(add-hook 'rust-mode-hook | |
(lambda () | |
(define-key rust-mode-map (kbd "<S-f5>") 'cargo-test))) | |
(add-hook 'rust-mode-hook | |
(lambda () | |
(define-key rust-mode-map (kbd "<C-S-f5>") 'cargo-bench))) | |
(add-hook 'rust-mode-hook | |
(lambda () | |
(define-key rust-mode-map (kbd "<f4>") 'rust-save-compile-and-run-this))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment